首页 > 其他 > 详细

请求头加引号工具

时间:2019-10-05 12:19:17      阅读:207      评论:0      收藏:0      [点我收藏+]

请求头中加引号工具

技术分享图片
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!