以下是代码
import requests
from bs4 import BeautifulSoup as bs
zhihu='https://www.zhihu.com/#signin'
def login():
header = {
"Accept": "*/*",
"Accept-Encoding": "gzip,deflate",
"Accept-Language": "en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4",
"Connection": "keep-alive",
"Content-Type": " application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
"Referer": "http://www.zhihu.com/"
}
s = requests.session()
cookie = bs(s.get('https://www.zhihu.com', headers=header).content).find(type='hidden')['value']
print(cookie)
post_data = {'_xsrf': cookie, 'password': 'xxx','captcha_type':'cn','remember_me': True,'email': 'xxxx'}
p=s.post(url=zhihu, data=post_data, headers=header)
print(p)
r = s.get(url=zhihu)
if __name__ == '__main__': # 程序运行入口
login()
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.