返回密码[Python]小练习 模拟登陆人人网返回密码
生活随笔
收集整理的這篇文章主要介紹了
返回密码[Python]小练习 模拟登陆人人网返回密码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
改章節筆者在北京喝咖啡的時候突然想到的...之前就有想寫幾篇關于返回密碼的博客,所以回家到之后就奮筆疾書的寫出來發布了
總得思緒很簡單:
獲得一個cookie
裝載好自己的request
發送請求
每日一道理
成熟是一種明亮而不刺眼的光輝,一種圓潤而不膩耳的音響,一種不需要對別人察顏觀色的從容,一種終于停止了向周圍申訴求告的大氣,一種不理會哄鬧的微笑,一種洗刷了偏激的淡漠,一種無須聲張的厚實,一種并不陡峭的高度。
#coding:utf8
'''
模擬陸登人人 根據網上的資料和firefox做了下
首先自己去探查了下
面頁素元:
<input id="email" class="input-text" type="text" value="" tabindex="1" name="email"></input
<input id="password" class="input-text" type="password" autocomplete="off" tabindex="2" error="請輸入密碼" name="password"></input>
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,蘋果還是蘋果,暴雪還是暴雪,而這些牛人離開了公司,自己什么都不是。
總結
以上是生活随笔為你收集整理的返回密码[Python]小练习 模拟登陆人人网返回密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows上使用netsh命令设置I
- 下一篇: 常用钢材种类