码迷,mamicode.com
首页 > 其他好文 > 详细

请求头加引号工具

时间:2019-10-05 14:24:18      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:any   line   doctype   class   nes   int   gif   代码   code   

请求头中加引号工具

技术图片
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",
技术图片

请求头加引号工具

标签:any   line   doctype   class   nes   int   gif   代码   code   

原文地址:https://www.cnblogs.com/youxiu123/p/11624343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!