爬虫之请求头中加引号工具
请求头中加引号工具
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",