#模拟登陆
import requests
# cookie
posturl="http://pythonscraping.com/pages/cookies/welcome.php"
userdata={'username':'zhangsan','password':'password'}
postres=requests.post(posturl,userdata)
print(postres.cookies)
print(postres.cookies.get_dict())
getres=requests.get(posturl,cookies=postres.cookies)
print(getres.text)
# session
mysession=requests.Session()
posturl="http://pythonscraping.com/pages/cookies/welcome.php"
userdata={'username':'lisi','password':'password'}
r=mysession.post(posturl,userdata)
print(r.cookies)
print(r.cookies.get_dict)
getres=mysession.get(posturl)
print(getres.text)
# 模拟登陆实例
# 登陆平台 http://www.dajiangtai.com/login.do
# 抓包工具fiddler https://www.telerik.com/fiddler
import requests
posturl="http://www.dajiangtai.com/login.do"
myses=requests.Session()
logindata={"browser":'','system':'Win10(9888)','email':'15088566830','password':'304892415'} # 从fiddler中监控获取
r=mysession.post(posturl,logindata)
# 模拟测试
myurl="http://www.dajiangtai.com/user/course.do"
res=mysession.get(myurl)
print(res.text)

image.png

image.png

image.png
网友评论