我一直在尝试使python脚本登录到我的reddit帐户,但它似乎没有工作,有人可以告诉我最新错误与我的代码?它运行良好它只是不login.¨python 3使用urllib和cookiejar在网页上登录表单
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
authentication_url = 'https://ssl.reddit.com/post/login'
payload = {
'op': 'login',
'user_name': 'username',
'user_pass': 'password'
}
data = urllib.parse.urlencode(payload)
binary_data = data.encode('UTF-8')
req = urllib.request.Request(authentication_url, binary_data)
resp = urllib.request.urlopen(req)
contents = resp.read()
不要用分号来终止行。 Python不需要它们。 – Blender
另外,请考虑使用[请求](http://python-requests.org/) – ThiefMaster