【Python】解析浏览器中的header请求头为JSON格式
2023-09-11 14:16:50 时间
一、浏览器中的请求头复制到文件中
二、代码解析
#!/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')
三、解析效果
相关文章
- python爬虫知识点总结(十一)使用Selenium模拟浏览器抓取淘宝商品美食信息
- Python--深入浅出的装饰器--2
- 2023版python安装教程奉上,Python永久使用 超详细版,一看就会【小白友好】
- python入门常用方法(转json,模拟浏览器请求头,写入文件)
- 【Python】【PyPI】twine模块打包python项目上传pypi
- python中OrderedDict的使用
- Python基础随机数库——random
- python读取文件,读取json文件
- python学习之基于Python的人脸识别技术学习
- Python 数据分析教程之如何验证线性回归的假设,线性回归的假设是什么?以及如何用python验证它们?
- 【Python基础】我的第一个 python 程序
- python经常使用的十进制、16进制、字符串、字节串之间的转换(长期更新帖)
- python 获得拼音首字母
- Python 框架 之 Django 绑定 MySql ,MVT 实现简单一个简单的浏览器(内附详细步骤)
- Python 基础 之 python 进程知识点整理,实现一个简单使用进程池的多进程文件夹文件copy器
- Python用python-docx读写word文档
- 【Python】python 库分类大全
- 100本Python精品书籍(附pdf电子书下载)
- 【python 学习】——pycharm终端解释器和Python解释器配置
- [Python]python+yaml三行代码完成配置文件灵活读取与warning:YAMLLoadWarning处理
- Selenium4 Python实现Page Factory设计模式,python新的定位方法
- Python 导入分部分项前的 数据处理