python模拟登录百度贴吧(百度贴吧登录)实例
时间:2023-11-20 14:30:56
![]() |
# -*- 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)
"""获取数据"""
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)
"""获取数据"""
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('帐号','密码')
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用pyserial进行串口通信的实例
sina和265天气预报调用代码
python实现字符串和数字拼接
![](https://img.aspxhome.com/file/2023/6/128596_0s.jpg)
13个你希望早点知道的实用WordPress SQL查询语句[译]
![](https://img.aspxhome.com/file/UploadPic/20102/28/sqlbox-14s.jpg)
js 代码优化点滴记录
简单谈谈python中的语句和语法
python如何调用现有的matlab函数
![](https://img.aspxhome.com/file/2023/9/134919_0s.png)
Python爬虫抓取技术的一些经验
![](https://img.aspxhome.com/file/2023/0/76760_0s.jpg)
MySQL优化之数据类型的使用
用python写个博客迁移工具
![](https://img.aspxhome.com/file/2023/2/69002_0s.gif)
Python中import导入不同目录的模块方法详解
在Python 字典中一键对应多个值的实例
MySQL死锁的产生原因以及解决方案
php tpl模板引擎定义与使用示例
Python一句代码实现找出所有水仙花数的方法
[翻译]标记语言和样式手册 Chapter 9 精简标签
![](https://img.aspxhome.com/file/UploadPic/20082/1/20082110109651s.jpg)
js显示动态时间的方法详解
![](https://img.aspxhome.com/file/2023/0/129580_0s.jpg)
python调试工具Birdseye的使用教程
![](https://img.aspxhome.com/file/2023/4/93714_0s.gif)
python使用matplotlib绘制折线图
![](https://img.aspxhome.com/file/2023/2/135162_0s.jpg)