python模拟登录知乎
# -*- coding:utf-8 -*- import urllib import urllib2 import cookielib import sys from bs4 import BeautifulSoup reload(sys) sys.setdefaultencoding("utf-8") class login(): zhihuurl="https://www.zhihu.com/#signin" def __init__(self): self.loginurl="https://www.zhihu.com/login/email" self.data={"_xsrf":"d9d05c3ecd636d3515482ee011e040c9","password":"xxxx","remember_me":"true","email":"791962385@qq.com"} self.postdata=urllib.urlencode(self.data) self.cj=cookielib.CookieJar() self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) def getinfo(self): request=urllib2.Request(url=self.loginurl,data=self.postdata) result=self.opener.open(request) result2=self.opener.open(self.zhihuurl) print result2.read() if __name__ == '__main__': test=login() test.getinfo()