headers 替换脚本

python代码

   headers = """
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
"""
hs = headers.split('\n')
b = [k for k in hs if len(k)]
e = b
f = {(i.split(":")[0], i.split(":", 1)[1].strip()) for i in e}
g = sorted(f)
index = 0
print("{")
for k, v in g:
        print(repr(k), repr(v), sep=':', end=",\n")
print("}")

pycharm直接替换

(.*?):\s(.*)
'$1':'$2',
posted @ 2018-11-13 15:28  公众号python学习开发  阅读(358)  评论(0编辑  收藏  举报