python
https://blog.csdn.net/qq_34246164/article/details/81610896
import requests
import time
mycookie = { "PHPSESSID":"56v9clgo1kdfo3q5q8ck0aaaaa" }
x = requests.session()
x.get("http://127.0.0.1:80",cookies = mycookie)
time.sleep(5)
x.get("http://127.0.0.1:80")
运行脚本后,通过抓包发现,第一次get请求的中含有我自定义的cookie,第二次请求中却没有。因为我要对很多http接口发送请求,所以如果在每个get里面都加入一个cookie变量的话,写起来就有些麻烦了。于是google了一下,找到了如下的解决方法:
import requests
import time
mycookie = { "PHPSESSID":"56v9clgo1kdfo3q5q8ck0aaaaa" }
x = requests.session()
requests.utils.add_dict_to_cookiejar(x.cookies,{"PHPSESSID":"07et4ol1g7ttb0bnjmbiqjhp43"})
x.get("http://127.0.0.1:80",cookies = mycookie)
time.sleep(5)
x.get("http://127.0.0.1:80")
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16