编程语言
首页 > 编程语言> > python-转化请求头

python-转化请求头

作者:互联网

转化请求头

import re
 
headers = """
 
 
 
 
 
 
 
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Host: movie.douban.com
Referer: https://movie.douban.com/subject/27010768/comments?start=420&limit=20&sort=new_score&status=P
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
X-Requested-With: XMLHttpRequest
 
"""
 
 
 
pattern = '^(.*?): (.*?)$'
#               1   2
for line in headers.splitlines(): # 反向引用
    print(re.sub(pattern, '\'\\1\': \'\\2\',',  line))

标签:douban,zh,请求,python,movie,Accept,转化,re,Sec
来源: https://www.cnblogs.com/luoxian1011/p/15858423.html