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)