Python模拟登录知乎出现的403问题

python# -*- coding:utf-8 -*-

import requests
from bs4 import BeautifulSoup as bs

loginurl = 'http://www.zhihu.com/'

s = requests.session()
headers = {
        'Referer':'http://www.zhihu.com/', 
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36'
}

data = {
        '_xsrf': bs(s.get(loginurl, headers = headers).content).find(type='hidden')['value'],
        'email': 'email',
        'password': 'passworld',
        'rememberme': 'y'
}

r = s.post(loginurl, data = data, headers = headers)
print r.text

结果是:
<html><title>403: Forbidden</title><body>403: Forbidden</body></html>

希望得到前辈们的指点,万分感谢!

阅读 7.6k
2 个回答
loginurl = 'http://www.zhihu.com/login'
新手上路,请多包涵

我试了,还是不行啊。
我改了下代码,现在是报这个错:
<html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题