python爬虫头部文件自动加引号脚本

2022-07-14 16:56:24 浏览数 (1)

代码语言:javascript复制
import re

headers_str = '''
formhash: f0f241b5
qdxq: nu
qdmode: 2
todaysay: 
fastreply: 0
'''
pattern = '^(.*?): (.*)$'

for line in headers_str.splitlines():
    print(re.sub(pattern, ''\1': '\2',', line))            

0 人点赞