#coding:utf-8 import requests import urllib3 import time class Zhihu: def __init__(self): self.loginurl='' self.indexurl='https://www.zhihu.com/' self.cookies='' self.headers={ 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36' } self.s='' self.posturl='https://www.zhihu.com/login/email' def get_xsrf(self): requests.packages.urllib3.disable_warnings() s =requests.session() self.s=s res = s.get(self.indexurl,headers=self.headers,verify=False) self.cookies=res.cookies return res.cookies['_xsrf'] def get_post(self): data={ "_xsrf":self.get_xsrf(), "password":"wxxxx@", "email":"10000@qq.com", "captcha":self.get_captcha(), 'captcha_type': 'en' } print data requests.packages.urllib3.disable_warnings() res = self.s.post(self.posturl, headers=self.headers, verify=False,data=data) print res.content def get_captcha(self): t=str(int(time.time())) captcha_url='http://www.zhihu.com/captcha.gif?r=1466595391805&type=login&lang=en' res = self.s.get(captcha_url,headers=self.headers) content =res.content pic= open('./t1.gif','wb') pic.write(content) pic.close() captcha= raw_input('captcha : ') return captcha obj = Zhihu() obj.get_post()
http://www.jianshu.com/p/50c5815bb60b#
http://blog.csdn.net/hudeyu777/article/details/76706007