import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
}
url = 'http://xxx.xxx.xxx'
resp = requests.get(url, headers)
source_cookies = resp.cookies.get_dict() # 请求网站后返回的Cookie
print(source_cookies)
resp = requests.get(url, headers, cookies=cookies) # 向请求头中添加服务器返回的Cookie
print(resp.text.encode('utf-8', errors='ignore'))
print(resp.status_code)
cookies = resp.cookies.get_dict()
print(cookies)
使用requests获取并向headers中添加cookie
于 2019-03-13 21:31:17 首次发布