JohnKris
JohnKris
采纳率0%
2016-03-01 06:54 阅读 2.6k

python 模拟登录知乎,登录不成功

import urllib2
import urllib
import cookielib
import ssl

filename = '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”
读到的网页内容,也总是登录那一页,求教怎么才能模拟登录成功?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • devmiao devmiao 2016-03-02 11:34
    点赞 1 评论 复制链接分享
  • oyljerry oyljerry 2016-03-02 11:33

    你提交的http数据应该还要不对的地方 所有zhihu没有通过

    点赞 评论 复制链接分享

相关推荐