简单粗暴,直接复制到内容,运行就行 小缺点:运行出来的请求头里面可能有双引号引起来的,比如sec-ch-ua,会报错,手动改一下,改成单引号,完美解决
import json
headers = """
authority: www.xiaohongshu.com
method: GET
path: /discovery/item/619df492000000002103712e
scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9,en;q=0.8,ru;q=0.7
cache-control: max-age=0
cookie: customerClientId=575642782579767; xhsTrackerId=f2d4fb13-5552-40f2-c085-503faeeaccb7; extra_exp_ids=commentshow_clt1,gif_exp1,ques_clt2; xhsTracker=url=index&searchengine=baidu; timestamp2=20220223321b8d9e13260903288982fc; timestamp2.sig=KjEGZZt2JivgOolaZLcyrNTuFbIEeNkhfGkLj8PIjbs
dnt: 1
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36
"""
def create_headers(headers):
headers = headers.strip().split('\n')
headers = {x.split(':')[0].strip(): ("".join(x.split(':')[1:])).strip().replace('//', "://") for x in headers}
return json.dumps(headers,indent=1)
print(create_headers(headers))
|