python模擬登錄百度貼吧(百度貼吧登錄)實(shí)例
![]() |
# -*- 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')))
"""------輸入帳號(hào)密碼------"""
login('帳號(hào)','密碼')
# -*- 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')))
"""------輸入帳號(hào)密碼------"""
login('帳號(hào)','密碼')
相關(guān)文章
python調(diào)用c++ ctype list傳數(shù)組或者返回?cái)?shù)組的方法
今天小編就為大家分享一篇python調(diào)用c++ ctype list傳數(shù)組或者返回?cái)?shù)組的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02Python中WatchDog的使用經(jīng)驗(yàn)總結(jié)
在?python?中文件監(jiān)視主要有兩個(gè)庫(kù),一個(gè)是?pyinotify,一個(gè)是?watchdog,本文主要為大家詳細(xì)介紹一下Python中WatchDog的使用相關(guān)經(jīng)驗(yàn),感興趣的小伙伴可以了解下2023-12-12Python實(shí)現(xiàn)的根據(jù)IP地址計(jì)算子網(wǎng)掩碼位數(shù)功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)的根據(jù)IP地址計(jì)算子網(wǎng)掩碼位數(shù)功能,涉及Python數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2018-05-05python函數(shù)超時(shí)自動(dòng)退出的實(shí)操方法
在本篇文章里小編給大家整理的是一篇關(guān)于python函數(shù)超時(shí)自動(dòng)退出的實(shí)操方法,有需要的朋友們可以學(xué)習(xí)下。2020-12-12Django數(shù)據(jù)庫(kù)如何在原有表中添加新字段
這篇文章主要介紹了Django數(shù)據(jù)庫(kù)如何在原有表中添加新字段問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09tensorflow將圖片保存為tfrecord和tfrecord的讀取方式
今天小編就為大家分享一篇tensorflow將圖片保存為tfrecord和tfrecord的讀取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02