cookie 问题
第一次 储存cookie程序代码:
import requests,json s = requests.session() a = s.get("https://www.baidu.com") cookies = requests.utils.dict_from_cookiejar(s.cookies) with open(".\cook.txt", "w") as fp: json.dump(cookies, fp)
第二次 读取使用cookie会错报 TypeError: string indices must be integers
程序代码:
import requests,json f = open('./cook.txt', 'r',encoding='UTF-8') cookies=f.read() f.close() s = requests.session() a = s.get("https://www.baidu.com",cookies=cookies)