一、浏览器中的请求头复制到文件中
二、代码解析
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time :2022/4/3 22:37
@Author :
@File :header.py
@Version :1.0
@Function:
"""
import json
def headerAnalysis(headerPath):
"""
浏览器中的header解析成JSON
:param headerPath:
:return:
"""
headerJson = {}
with open(headerPath, 'r', encoding='utf-8') as f:
data = f.readlines()
for i in data:
h = i.split(': ')
if h[1].endswith('\n'):
h[1] = h[1][:-1]
headerJson.update({h[0]: h[1]})
print(json.dumps(headerJson, sort_keys=True, indent=4, separators=(',', ':'), ensure_ascii=False))
if __name__ == '__main__':
headerAnalysis(r'C:\Users\Desktop\header.txt')
三、解析效果