博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
返回密码[Python]小练习 -- 模拟登陆人人网返回密码
阅读量:4306 次
发布时间:2019-06-06

本文共 2044 字,大约阅读时间需要 6 分钟。

改章节笔者在北京喝咖啡的时候突然想到的...之前就有想写几篇关于返回密码的博客,所以回家到之后就奋笔疾书的写出来发布了

    总得思绪很简单:

    获得一个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,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。

转载于:https://www.cnblogs.com/jiangu66/archive/2013/04/21/3033385.html

你可能感兴趣的文章
vnpy学习_04回测评价指标的缺陷
查看>>
ubuntu终端一次多条命令方法和区别
查看>>
python之偏函数
查看>>
vnpy学习_06回测结果可视化改进
查看>>
读书笔记_量化交易如何建立自己的算法交易01
查看>>
设计模式03_工厂
查看>>
设计模式04_抽象工厂
查看>>
设计模式05_单例
查看>>
设计模式06_原型
查看>>
设计模式07_建造者
查看>>
设计模式08_适配器
查看>>
设计模式09_代理模式
查看>>
设计模式10_桥接
查看>>
设计模式11_装饰器
查看>>
设计模式12_外观模式
查看>>
设计模式13_享元模式
查看>>
设计模式14_组合结构
查看>>
设计模式15_模板
查看>>
海龟交易法则01_玩风险的交易者
查看>>
CTA策略02_boll
查看>>