python模擬登錄百度貼吧(百度貼吧登錄)實例
![]() |
# -*- coding:utf-8 -*-
# python3.3.3
import sys,time,re,urllib.parse,urllib.request,http.cookiejar,random,math,os.path,hashlib,json,binascii,threading
"""cookie"""
cookie=http.cookiejar.LWPCookieJar()
#cookie.load('f:/cookie.txt',True,True)
chandle=urllib.request.HTTPCookieProcessor(cookie)
"""獲取數(shù)據(jù)"""
def getData(url):
r=urllib.request.Request(url)
opener=urllib.request.build_opener(chandle)
u=opener.open(r)
#chandle.cookiejar.save('f:/cookie.txt',True,True)
data=u.read()
try:
data=data.decode('utf-8')
except:
data=data.decode('gbk','ignore')
return data
def postData(url,data):
data=urllib.parse.urlencode(data);data=bytes(data,'utf-8')
r=urllib.request.Request(url,data)
opener=urllib.request.build_opener(chandle)
u=opener.open(r)
#chandle.cookiejar.save('f:/cookie.txt',True,True)
data=u.read()
try:
data=data.decode('utf-8')
except:
data=data.decode('gbk','ignore')
return data
def login(name,pwd):
url='http://www.baidu.com'
getData(url)
par={
"apiver":'v3',
"callback":'bd__cbs__oug2fy',
"class":'login',
"logintype":'dialogLogin',
"tpl":'tb',
"tt":'1385013373144'
}
url='https://passport.baidu.com/v2/api/?getapi&%s' % urllib.parse.urlencode(par)
token=re.findall('"token" : "(.*?)"',getData(url))[0]
par.update({"isphone":'false',"username":name,"token":token})
url='https://passport.baidu.com/v2/api/?logincheck&?%s' % urllib.parse.urlencode(par)
data={
"charset":'GBK',
"mem_pass":'on',
"password":pwd,
"ppui_logintime":'1612376',
"quick_user":'0',
"safeflg":'0',
"splogin":'rate',
"u":'http://tieba.baidu.com/'
}
url='https://passport.baidu.com/v2/api/?login'
par.update(data)
bdu=re.findall('hao123Param=(.*?)&',postData(url,par))[0]
par={
"bdu":bdu,
"t":'1385013373144'
}
url='http://user.hao123.com/static/crossdomain.php?%s' % urllib.parse.urlencode(par)
getData(url)
print(json.loads(getData('http://tieba.baidu.com/f/user/json_userinfo')))
"""------輸入帳號密碼------"""
login('帳號','密碼')
# -*- coding:utf-8 -*-
# python3.3.3
import sys,time,re,urllib.parse,urllib.request,http.cookiejar,random,math,os.path,hashlib,json,binascii,threading
"""cookie"""
cookie=http.cookiejar.LWPCookieJar()
#cookie.load('f:/cookie.txt',True,True)
chandle=urllib.request.HTTPCookieProcessor(cookie)
"""獲取數(shù)據(jù)"""
def getData(url):
r=urllib.request.Request(url)
opener=urllib.request.build_opener(chandle)
u=opener.open(r)
#chandle.cookiejar.save('f:/cookie.txt',True,True)
data=u.read()
try:
data=data.decode('utf-8')
except:
data=data.decode('gbk','ignore')
return data
def postData(url,data):
data=urllib.parse.urlencode(data);data=bytes(data,'utf-8')
r=urllib.request.Request(url,data)
opener=urllib.request.build_opener(chandle)
u=opener.open(r)
#chandle.cookiejar.save('f:/cookie.txt',True,True)
data=u.read()
try:
data=data.decode('utf-8')
except:
data=data.decode('gbk','ignore')
return data
def login(name,pwd):
url='http://www.baidu.com'
getData(url)
par={
"apiver":'v3',
"callback":'bd__cbs__oug2fy',
"class":'login',
"logintype":'dialogLogin',
"tpl":'tb',
"tt":'1385013373144'
}
url='https://passport.baidu.com/v2/api/?getapi&%s' % urllib.parse.urlencode(par)
token=re.findall('"token" : "(.*?)"',getData(url))[0]
par.update({"isphone":'false',"username":name,"token":token})
url='https://passport.baidu.com/v2/api/?logincheck&?%s' % urllib.parse.urlencode(par)
data={
"charset":'GBK',
"mem_pass":'on',
"password":pwd,
"ppui_logintime":'1612376',
"quick_user":'0',
"safeflg":'0',
"splogin":'rate',
"u":'http://tieba.baidu.com/'
}
url='https://passport.baidu.com/v2/api/?login'
par.update(data)
bdu=re.findall('hao123Param=(.*?)&',postData(url,par))[0]
par={
"bdu":bdu,
"t":'1385013373144'
}
url='http://user.hao123.com/static/crossdomain.php?%s' % urllib.parse.urlencode(par)
getData(url)
print(json.loads(getData('http://tieba.baidu.com/f/user/json_userinfo')))
"""------輸入帳號密碼------"""
login('帳號','密碼')
相關文章
python調(diào)用c++ ctype list傳數(shù)組或者返回數(shù)組的方法
今天小編就為大家分享一篇python調(diào)用c++ ctype list傳數(shù)組或者返回數(shù)組的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02Python中WatchDog的使用經(jīng)驗總結(jié)
在?python?中文件監(jiān)視主要有兩個庫,一個是?pyinotify,一個是?watchdog,本文主要為大家詳細介紹一下Python中WatchDog的使用相關經(jīng)驗,感興趣的小伙伴可以了解下2023-12-12Python實現(xiàn)的根據(jù)IP地址計算子網(wǎng)掩碼位數(shù)功能示例
這篇文章主要介紹了Python實現(xiàn)的根據(jù)IP地址計算子網(wǎng)掩碼位數(shù)功能,涉及Python數(shù)值運算相關操作技巧,需要的朋友可以參考下2018-05-05Django數(shù)據(jù)庫如何在原有表中添加新字段
這篇文章主要介紹了Django數(shù)據(jù)庫如何在原有表中添加新字段問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09tensorflow將圖片保存為tfrecord和tfrecord的讀取方式
今天小編就為大家分享一篇tensorflow將圖片保存為tfrecord和tfrecord的讀取方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02