问题描述
- python 模拟登录知乎,登录不成功
-
import urllib2
import urllib
import cookielib
import sslfilename = 'cookie.txt'
cookie = cookielib.MozillaCookieJar(filename)
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)postData = urllib.urlencode({
'account':'krishna_liang@163.com',
'password':'1liangwei',
'_xsrf':'0764ca863ddcde749667d4aedd21d341',
'remember_me':True
})
ssl._create_default_https_context = ssl._create_unverified_context
loginUrl = 'http://www.zhihu.com/login/email'
try:
result = opener.open(loginUrl,postData)
except urllib2.HTTPError,e:
print e.code
except urllib2.URLError,e:
print e.reason
else:
print "OK"#print result.read()
cookie.save(ignore_discard=True,ignore_expires=True)
gradeUrl = 'https://www.zhihu.com'
result = opener.open(gradeUrl)
print result.read()
result = opener.open(loginUrl,postData)这句总是输入“OK”
读到的网页内容,也总是登录那一页,求教怎么才能模拟登录成功?
解决方案
https://www.zhihu.com/question/29925879
解决方案二:
你提交的http数据应该还要不对的地方 所有zhihu没有通过