python3.3教程之模拟百度登陆代码分享
时间:2023-08-02 23:08:23
#-*-coding:utf-8-*-
'''
Created on 2014年1月10日
@author: hhdys
'''
import urllib.request,http.cookiejar,re
class Baidu:
def login(self):
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36')]
resp=opener.open('http://weigou.baidu.com/')
for c in cj:
print(c.name,"====",c.value)
getapiUrl = "https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true"
resp2=opener.open(getapiUrl)
getapiRespHtml = resp2.read().decode("utf-8")
foundTokenVal = re.search("bdPass\.api\.params\.login_token='(?P<tokenVal>\w+)';", getapiRespHtml)
if foundTokenVal :
tokenVal = foundTokenVal.group("tokenVal")
print(tokenVal)
staticpage = "http://zhixin.baidu.com/Jump/index?module=onesite"
baiduMainLoginUrl = "https://passport.baidu.com/v2/api/?login"
postDict = {
'charset':"utf-8",
'token':tokenVal,
'isPhone':"false",
'index':"0",
'staticpage': staticpage,
'loginType': "1",
'tpl': "mn",
'callback': "parent.bd__pcbs__n1a3bg",
'username':"*****", #用户名
'password':"*****", #密码
'mem_pass':"on",
"apiver":"v3",
"logintype":"basicLogin"
}
postData = urllib.parse.urlencode(postDict);
postData = postData.encode('utf-8')
resp3=opener.open(baiduMainLoginUrl,data=postData)
for c in cj:
print(c.name,"="*6,c.value)
if __name__=="__main__":
print("="*10,"开始")
bd=Baidu()
bd.login()
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL中MIN()函数的使用教程
python回溯法实现数组全排列输出实例分析
详解Python如何查看一个函数的参数
php全局变量和类配合使用深刻理解
Python中np.percentile和df.quantile分位数详解
![](https://img.aspxhome.com/file/2023/7/97527_0s.png)
解决vue项目 build之后资源文件找不到的问题
![](https://img.aspxhome.com/file/2023/3/133003_0s.jpg)
python3操作微信itchat实现发送图片
![](https://img.aspxhome.com/file/2023/3/76743_0s.jpg)
PHP中大于2038年时间戳的问题处理方案
python爬虫 urllib模块url编码处理详解
解读golang plugin热更新尝试
关于命令行执行Python脚本的传参方式
MYSQL子查询和嵌套查询优化实例解析
一文详解Golang中new和make的区别
python读取Excel实例详解
python mysql中in参数化说明
10分钟用Python快速搭建全文搜索引擎详解流程
![](https://img.aspxhome.com/file/2023/1/67321_0s.png)
keras 解决加载lstm+crf模型出错的问题
mysql 8.0.16 压缩包安装配置方法图文教程
![](https://img.aspxhome.com/file/2023/8/119728_0s.jpg)
Python提取Word中图片的实现步骤
![](https://img.aspxhome.com/file/2023/3/105723_0s.png)