我正在使用位于here
的httplib2库到目前为止,我的代码是:
http = httplib2.Http()
url= 'http://www.reddit.com/api/login'
body= {'user' : 'DUMMYUSERNAME', 'passwd': 'DUMMYPASSWORD'}
headers = {'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
response, content= http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
headers = {'Cookie': response['set-cookie']}
我可能会弄错,但我相信上面的代码会成功将我登录到reddit.com(我将如何验证这一点?)
下一步是发送评论。我看了一下Firebug中的网络选项卡,看起来表单需要几个变量:
id #form-t3_f3oj23a4
r learnprogramming
renderstyle html
text testing send data
thing_id t3_f3oj2
uh 6qsck0zhpa2585dac6a0ab49250cbceca76fb36df883320896
但我不确定
会是这样的吗?
data= dict(thing_id="t3_f3oj2", text="testing", id="#form-t3_f3oj2ikj", r="learnprogramming", uh="sz4n7idqmc22bdeec21d7f2ca3e9408b102160646e2fcbbff4", renderstyle="html")
resp, content = h.request("http://www.reddit.com/r/blahblahsubreddit/comments/f3oj2/blahblahpost/", "POST", urllib.urlencode(data))
我使用的是合适的库吗?感谢。