热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

高效添加HTTP请求头字段

代码:headersAccept:texthtml,applicationxhtml+xml,applicationxml;q0.9,imagewebp,image

代码:

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("\n")])
 
#输出测试
print(headers)


推荐阅读
author-avatar
老薛很厚道
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有