request请求头快速加引号

2022-07-14 16:33:49 浏览数 (1)

代码语言:javascript复制
import re

headers_str = '''
origin: https://sou.zhaopin.com
referer: https://sou.zhaopin.com/?p=3&jl=765&kw=python&kt=3
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36
'''
pattern = '^(.*?): (.*)$'

for line in headers_str.splitlines():
    print(re.sub(pattern, ''1': '2',', line))

0 人点赞