侧边栏壁纸
博主头像
海绵

正向的根基决定逆向的上限

  • 累计撰写 30 篇文章
  • 累计创建 28 个标签
  • 累计收到 19 条评论

利用正则给请求头加引号

海绵
2022-01-18 / 0 评论 / 0 点赞 / 312 阅读 / 600 字

import re

headers_str = """
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Host: www.51pyblog.com
Pragma: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
"""
pattern = '^(.*?): (.*)$'
for line in headers_str.splitlines():
    print(re.sub(pattern, '\'\\1\': \'\\2\',', line))

image.png

0

评论区