text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding:
gzip, deflate, br
Accept-Language:
zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Cache-Control:
max-age=0
Connection:
keep-alive
Cookie:
BIDUPSID=4F35A99C2D0F8233AADB36BA2B6909ED; PSTM=1696333643; BAIDUID=E4EC93535B0310C56190403CD6CD43A6:FG=1; BD_HOME=1; BD_UPN=12314753; BA_HECTOR=0h01ah8ga18h20248l0l85803335ao1jihl831u; BAIDUID_BFESS=E4EC93535B0310C56190403CD6CD43A6:FG=1; ZFY=0cEH4d4x9VocBj26zMuDuxmYT3S:BDocX4TImHafZKfs:C
Host:
www.baidu.com
Sec-Ch-Ua:
"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"
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/124.0.0.0 Safari/537.36
X-Forwarded-For:
192.192.27.29
X-Forwarded-Proto:
https
复制网页中的请求头时,往往出来的是上面这种格式——key和value各占一行,尝试了论坛中的请求头转换工具,好像没有能处理这种格式的
一般处理的格式为key与value在同一行,用英文格式冒号分隔,如下:
[Python] 纯文本查看 复制代码Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Cookie:BIDUPSID=4F35A99C2D0F8233AADB36BA2B6909ED; PSTM=1696333643; BAIDUID=E4EC93535B0310C56190403CD6CD43A6:FG=1; BD_HOME=1; BD_UPN=12314753; BA_HECTOR=0h01ah8ga18h20248l0l85803335ao1jihl831u; BAIDUID_BFESS=E4EC93535B0310C56190403CD6CD43A6:FG=1; ZFY=0cEH4d4x9VocBj26zMuDuxmYT3S:BDocX4TImHafZKfs:C
Host:www.baidu.com
Sec-Ch-Ua:"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"
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/124.0.0.0 Safari/537.36
X-Forwarded-For:192.192.27.29
X-Forwarded-Proto:https
于是写了一个小工具,用于实现将如上两种格式的请求头输入,转换成标准的headers格式,效果如下:
11.jpg (107.39 KB, 下载次数: 0)
下载附件
2024-11-4 22:17 上传
22.jpg (119.31 KB, 下载次数: 0)
下载附件
2024-11-4 22:18 上传
另外,由于我经常使用只带ua的请求头,所以当输入框为空时,点击“转换”,可生成一个默认的请求头
[Python] 纯文本查看 复制代码headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
}
33.jpg (56.45 KB, 下载次数: 0)
下载附件
2024-11-4 22:19 上传
————————————————————————————
源代码如下:
[Python] 纯文本查看 复制代码import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox
from PyQt5.QtGui import QClipboard, QFont, QColor
from PyQt5.QtCore import QMimeData
class HeadersConverter(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.setGeometry(300, 300, 800, 600)
self.setWindowTitle('Headers Converter')
self.setStyleSheet("background-color: #f0f0f0;")
self.input_text_edit = QTextEdit()
self.input_text_edit.setStyleSheet(
"background-color: #ffffff; border: 1px solid #cccccc; padding: 10px; border-radius: 10px;")
self.input_text_edit.setFont(QFont("微软雅黑", 12))
self.output_text_edit = QTextEdit(readOnly=True)
self.output_text_edit.setStyleSheet(
"background-color: #ffffff; border: 1px solid #cccccc; padding: 10px; border-radius: 10px;")
self.output_text_edit.setFont(QFont("微软雅黑", 12))
self.convert_button = QPushButton('转换')
self.convert_button.setStyleSheet(
"background-color: #4CAF50; color: #ffffff; border: none; padding: 10px 20px; border-radius: 5px;")
self.convert_button.setFont(QFont("微软雅黑", 12))
self.clear_button = QPushButton('清空')
self.clear_button.setStyleSheet(
"background-color: #FF9800; color: #ffffff; border: none; padding: 10px 20px; border-radius: 5px;")
self.clear_button.setFont(QFont("微软雅黑", 12))
self.copy_button = QPushButton('复制')
self.copy_button.setStyleSheet(
"background-color: #2196F3; color: #ffffff; border: none; padding: 10px 20px; border-radius: 5px;")
self.copy_button.setFont(QFont("微软雅黑", 12))
self.convert_button.clicked.connect(self.convert_headers)
self.clear_button.clicked.connect(self.clear_input)
self.copy_button.clicked.connect(self.copy_output)
button_layout = QHBoxLayout()
button_layout.addWidget(self.convert_button)
button_layout.addWidget(self.clear_button)
button_layout.addWidget(self.copy_button)
main_layout = QVBoxLayout()
main_layout.addWidget(self.input_text_edit)
main_layout.addWidget(self.output_text_edit)
main_layout.addLayout(button_layout)
self.setLayout(main_layout)
def convert_headers(self):
input_text = self.input_text_edit.toPlainText()
if not input_text:
output_text = 'headers = {\n'
output_text += ' "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",\n'
output_text += '}'
self.output_text_edit.setText(output_text)
else:
lines = input_text.split('\n')
lines = [line for line in lines if line.strip() != '']
formatted_headers = {}
i = 0
while i
——————————————————————————
成品如下:
通过百度网盘分享的文件:HeadersConverter.rar
链接:https://pan.baidu.com/s/1v3TY56Qp_2CW2S40AeAVQw?pwd=7q4j
提取码:7q4j