进来想研究一下python。百度了python登录结果。尝试了百度前几页的方法。发现都不行,这里是我的代码
import urllib2 import urllib import cookielib def renrenBrower(url,user,password): login_page = "http://passport.cnblogs.com/login.aspx" try: cj = cookielib.CookieJar() opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders = [('User-agent',r'Chrome/16.0.889.0')] data = urllib.urlencode({"__EVENTTARGET":"","__EVENTARGUMENT":"","__VIEWSTATE":"/FwEPDwULLTE1MzYzODg2NzZkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQtjaGtSZW1lbWJlcm1QYDyKKI9af4b67Mzq2xFaL9Bt","__EVENTVALIDATION":"/FwEWBQLWwpqPDQLyj/FOQAgK3jsrkBALR55GJDgKC3I","txtReturnUrl":"http://bboy.cnblogs.com"}) urllib2.install_opener(opener) login = urllib2.urlopen(login_page,data) return (unicode(login.read(),"utf8")) except Exception,e: print str(e) fp = open("post.html","wb") fp.write(renrenBrower("","",""))
首先:没有搞清楚原理,都是照着前辈们写的代码。但是没一个能成功的,不管是有人写的人人登录,还是博客园登录。都不可行。
代码介绍一下,这里的data字段是我抓包工具抓到的。一字不落的填上去的。不过不行。之前也试过用tbname。tbpassword等等表单字段提交。也不行。不知道是哪里出了问题~高手求带。
现行拜谢了~