请求头加引号工具

请求头中加引号工具

复制代码
import re

"""
正则匹配请求头加引号
"""

# 在下面输入需要添加引号的数据
headers_str = """


i: hello
from: AUTO
to: AUTO
smartresult: dict
client: fanyideskweb
salt: 15638914864826
sign: faff2d373872188bf8f622397fa158c1
ts: 1563891486482
bv: 53539dde41bde18f4a71bb075fcf2e66
doctype: json
version: 2.1
keyfrom: fanyi.web
action: FY_BY_CLICKBUTTION·    1是    


"""
#              1     2
pattern = r"^(.*?):s?(.*?$)"

for line in headers_str.splitlines():
    print(re.sub(pattern, r'"1": "2",', line))
复制代码

输出

复制代码
"i": "hello",
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
"salt": "15638914864826",
"sign": "faff2d373872188bf8f622397fa158c1",
"ts": "1563891486482",
"bv": "53539dde41bde18f4a71bb075fcf2e66",
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_CLICKBUTTION",
复制代码
原文地址:https://www.cnblogs.com/youxiu123/p/11624343.html