把cookie先写成字典形式,然后把字典转换为cookiejar import requestsfrom requests.cookies import cookiejar_from_dict# 注意:这个方法会替换掉原有的cookies# 开启一个会话Sessionsession = requests.Session()# 从chrome浏览器中取到的cookie值cookie_dict = { "49BAC005-7D5B-4231-8CEA-16939BEACD67": "cktest001", "JSESSIONID": "F4FFF69B8XXXXXXC8DCB4C061C0", "JSESSIONIDSSO": "9D49C76FD6XXXXXF294242B44A",}# 把cookie值转换为cookiejar类型,然后传给Sessionsession.cookies = cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True)print(session.cookies) 追加cookies import requestsfrom requests.cookies import RequestsCookieJar# 开启一个会话Sessionsession = requests.Session()# 创建一个Cookie Jar对象jar = RequestsCookieJar()# 向Cookie Jar对象中添加cookie值jar.set("49BAC005-7D5B-4231-8CEA-1XXXXBEACD67", "cktXXXX001")jar.set("JSESSIONID", "F4FFF69B8CXXXX80F0C8DCB4C061C0")jar.set("JSESSIONIDSSO", "9D49C7XXXX448FDF5B0F294242B44A")# 把cookies追加到Session中session.cookies.update(jar)print(session.cookies)