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>
希望得到前辈们的指点,万分感谢!