cookie和session的使用
import requests # 需要请求的目标地址 url= ' http://www.rrys2019.com/user/user ' headers ={ ' user-agent ' : ' Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Mobile Safari/537.36 ' } # 需要的登录地址 login_url= ' http://www.rrys2019.com/User/Login/ajaxLogin ' # 如果需要爬虫主动记录cookie并且携带cookie,那么在使用使用requests之前先调用session方法 # 并且使用session方法返回的对象发送请求即可 rep=requests.session() # 可以自动记录cookie data = { ' account ' : ' ' , ' password ' : ' ' , ' remember ' : ' 1 ' , ' url_back ' : ' http://www.rrys2019.com/user/user ' } res =rep.post(url=login_url,headers