模拟登陆基本原理,理解Post、Cookies和Session

import requests
#通过cookies登录
post_url='http://pythonscraping.com/pages/cookies/welcome.php'
userdata={"username":"zhangsan","password":"password"}
post_res=requests.post(post_url,userdata)
print(post_res.cookies.get_dict())
# print(post_res.text)
#通过session登录
mysession=requests.Session()
post_url='http://pythonscraping.com/pages/cookies/welcome.php'
userdata={"username":"lisi","password":"password"}
r=mysession.post(post_url,userdata)
print(r.cookies.get_dict())

posted @ 2019-10-01 20:02  天天见和  阅读(833)  评论(0编辑  收藏  举报