request请求把cookie当作参数传入请求
requests.cookies.RequestsCookieJar()
jar.set(key,value)
这里要注意的是对Cookie的处理,怎么遍历和提取的
headers = {
'Host':'www.jianshu.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36',
}
cookies = 'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2226065565%22%2C%22first_id%22%3A%2217b59029450769-04d60dc1f07d6d-c343365-921600-17b59029451bcc%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_utm_source%22%3A%22desktop%22%2C%22%24latest_utm_medium%22%3A%22timeline%22%7D%2C%22%24device_id%22%3A%2217b59029450769-04d60dc1f07d6d-c343365-921600-17b59029451bcc%22%7D'
jar = requests.cookies.RequestsCookieJar()
for cookie in cookies.split(';'):
key, value = cookie.split('=',1)
jar.set(key,value)
r3 = requests.get('http://www.jianshu.com',cookies = jar,headers=headers)
print(r3.text)
努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。