请求头加引号

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
import re

old_headers ='''
Accept: text/html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
'''

pattern = '^(.*?):[\s]*(.*?)$'
headers = ""
for line in old_headers.splitlines():
headers += (re.sub(pattern,'\'\\1\': \'\\2\',',line)) + '\n'
print(headers[:-2])

请求头加引号
http://cxycsx.vip/2023/08/31/其他/请求头加引号/
作者
程序员陈师兄
发布于
2023年8月31日
许可协议