python3.3教程之模拟百度登陆代码分享
#-*-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()
您可能感兴趣的文章:
- python3.3教程之模拟百度登陆代码分享
- python3.3教程之模拟百度登陆的代码
- python模拟登录百度代码分享(获取百度贴吧等级)
- python模拟登录百度代码分享(获取百度贴吧等级)
- Python模拟登陆淘宝并统计淘宝消费情况的代码实例分享
- Python模拟登陆淘宝并统计淘宝消费情况的代码实例分享
- python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
- python爬虫入门教程之点点美女图片爬虫代码分享
- python实现多线程暴力破解登陆路由器功能代码分享
- python爬虫入门教程之点点美女图片爬虫代码分享
- 使用python模拟登陆百度
- python爬虫之模拟登陆csdn的实例代码
- 【教程】手把手教你如何利用工具(IE9的F12)去分析模拟登陆网站(百度首页)的内部逻辑过程
- python爬虫入门教程之糗百图片爬虫代码分享
- python 采用代理模拟登陆代码
- 【教程】模拟登陆百度之Java代码版
- python运用decorate装饰器模拟网页登陆(含代码)
- python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
- 【教程】模拟登陆百度之Java代码版
- 【教程】手把手教你如何利用工具(IE9的F12)去分析模拟登陆网站(百度首页)的内部逻辑过程