代码:
headers = """Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Cache-Control: no-cache Connection: keep-alive Cookie: BAIDUID=C10B29E8D7B4C4A4F32FAD70B13CB890:FG=1; BIDUPSID=C10B29E8D7B4C4A4F32FAD70B13CB890; PSTM=1550911726; BD_UPN=12314353; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BDUSS=EpNWEJ4LXR5SEpOWlFZTTBNVWhBWXVoVzM1aU9GdlNDZFVKU3o2UVhIdnNTdTljSVFBQUFBJCQAAAAAAAAAAAEAAAAqacwJdGpwNDA5MjIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOy9x1zsvcdcU; H_PS_PSSID=1459_21127_29063_28519_28775_28720_28964_28835_28584_20719; H_PS_645EC=415cwPwqIfadTQMLwEwicJaKCoE%2B8%2BbL8y5rzZMvM8X8c5kSZca3ptObqOo; COOKIE_SESSION=72994_2_3_2_6_3_0_0_1_2_0_0_85642_11878_23_0_1558236612_1558097396_1558236589%7C9%2312374_11_1558097374%7C7; BDSVRTM=0 Host: www.baidu.com Pragma: no-cache Referer: https://www.baidu.com/ Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"""
执行:
headers = dict([line.split(": ",1) for line in headers.split(" ")]) #输出测试 print(headers)