cookie转字典 cookiejar相关的

str1="Cookie: anonymid=js5txwoc-mdawzp; depovince=GW; _r01_=1; JSESSIONID=abcPi5OivJCG47hnrAWJw; ick_login=0d403a11-f3c8-4d82-8282-a7f593dd4fce; jebe_key=d2b68b3d-d07e-4dfa-b5bb-79023ff79162%7Ccfcd208495d565ef66e7dff9f98764da%7C1550221615651%7C0; _de=537C8180D4C6307032E0B9ADC37B4602; jebecookies=35b1dc40-da72-454a-bd2c-357d209e59af|||||"

cookies={i.split("=")[0]:i.split('=')[1] for i in str1.split("; ")}
headers={"user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
         "x-requested-with": "XMLHttpRequest",
         }

 

只请求3次

import requests
from retrying import retry


@retry(stop_max_attempt_number=3)
def _parse_url(url):

    headers={"user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36", "x-requested-with": "XMLHttpRequest",}
    rs = requests.get(url,headers=headers)
    print(rs.cookies)
    return  rs


url = 'https://www.baidu.com'
cc=_parse_url(url)
# requests.utils.dict_from_cookiejar(rs.cookies)
# c = requests.utils.cookiejar_from_dict({'a': 'b'})

print(requests.utils.dict_from_cookiejar(cc.cookies))

cookie转字典 cookiejar相关的_第1张图片

cookie转字典 cookiejar相关的_第2张图片

你可能感兴趣的:(python)