改章节笔者在北京喝咖啡的时候突然想到的...之前就有想写几篇关于返回密码的博客,所以回家到之后就奋笔疾书的写出来发布了
总得思绪很简单:
获得一个cookie
装载好自己的request
发送请求
每日一道理 成熟是一种明亮而不刺眼的光辉,一种圆润而不腻耳的音响,一种不需要对别人察颜观色的从容,一种终于停止了向周围申诉求告的大气,一种不理会哄闹的微笑,一种洗刷了偏激的淡漠,一种无须声张的厚实,一种并不陡峭的高度。
#coding:utf8 '''模拟陆登人人 根据网上的资料和firefox做了下 首先自己去探查了下面页素元:cookie: jebecookies=523a9b12-658f-43c0-abf8-1ca1f3f87c10|||||; domain=.renren.com; path=/'''import re,urllib,urllib2,cookielib,codecs,chardet,sys class LoginRenRen(): def __init__(self,name='',password='',domain=''): self.name=name self.password=password self.domain=domain self.cj = cookielib.LWPCookieJar() try: #主动去程远获得一个cookie #self.cj.revert('renren.coockie') #试测的时候每次都有异常但是毫无影响,注释掉了也不影响 print 'successed got a cookie..' except Exception,e: print 'Can not get the cookies',e.message #装载cookies self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) urllib2.install_opener(self.opener) def login(self): params = {'domain':self.domain,'email':self.name,'password':self.password} req = urllib2.Request( 'http://www.renren.com/PLogin.do', urllib.urlencode(params) ) print 'login.....' self.openrate = self.opener.open(req) #查看下返回的url来判断陆登进去了没 print self.openrate.geturl() #info = self.openrate.read() #查看了一下面页码编 chardet是第三方库 #print chardet.detect(info) print '' #print re.findall(r'password',info) #打印出了返回的容内 type = sys.getfilesystemencoding() #print info.decode("UTF-8").encode(type) if __name__=='__main__': username = 'liuzhizhi123@126.com' #用户名 password = '4933848liu' #密码 domain = 'renren.com' ren = LoginRenRen(username,password,domain) ren.login()
文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。