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()
相關文章
pandas 對每一列數(shù)據(jù)進行標準化的方法
今天小編就為大家分享一篇pandas 對每一列數(shù)據(jù)進行標準化的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06
Python函數(shù)式編程指南(二):從函數(shù)開始
這篇文章主要介紹了Python函數(shù)式編程指南(二):從函數(shù)開始,本文講解了定義一個函數(shù)、使用函數(shù)賦值、閉包、作為參數(shù)等內(nèi)容,需要的朋友可以參考下2015-06-06
用python實現(xiàn)操縱mysql數(shù)據(jù)庫插入
大家好,本篇文章主要講的是用python實現(xiàn)操縱mysql數(shù)據(jù)庫插入,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下2022-01-01

