惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
I
InfoQ
Jina AI
Jina AI
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
量子位
月光博客
月光博客
罗磊的独立博客
雷峰网
雷峰网
The Cloudflare Blog
V
V2EX
小众软件
小众软件
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题

博客园 - CrossBug

python3.12 源码静态编译解决AttributeError: module 'sys' has no attribute 'winver' 随便存一下 不想跟上时间的步伐 pytesseract 修改源码后也报错f"{tesseract_cmd} is not installed or it's not in your PATH."解决方法 解决Can't open /usr/lib/grub/update-grub_lib 活了 世界无我 markdown_test 关于mimikatz在webshell运行 用户中心 - 博客园 可用性自动化V3 用户中心 - 博客园 关于sqlmap常用 思科设备各级密码: 关于时钟频率 Error when connecting to the GNS3 server: Cannot connect to http://127.0.0.1:3080. Please check if GNS3 is allowed in your antivirus and firewall. And that server version is 2.1.8. GNS3 Could桥接本地网卡报错:unable to create NIO Ethernet for bridge ' Error opening adapter: centos安装GNS3 GNS3 IOU VM
fiddler右键集成生成python requests请求代码
CrossBug · 2026-02-02 · via 博客园 - CrossBug

安装所需环境
npm install --global httpsnippet
打开fiddler->ctrl+r调出脚本编辑器,在class Handlers内添加以下代码
`// ==================== Python 代码生成(修复 BOM 问题)====================

// 1. Python Requests 右键菜单
public static ContextAction("Python-requests", "生成代码")
function DoPythonRequests(arrSess: Session[]) {
GeneratePythonCodeWithNode(arrSess, "requests");
}
// 2. Python http.client 右键菜单
public static ContextAction("Python-http.client", "生成代码")
function DoPythonHttpClient(arrSess: Session[]) {
GeneratePythonCodeWithNode(arrSess, "python3");
}
// 3. 核心生成函数(使用 Node.js + httpsnippet,自动移除 BOM)
public static function GeneratePythonCodeWithNode(oSessions: Session[], client: String) {
// 临时文件路径
var tempHar = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "fiddler_temp.har");
var tempHarFixed = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "fiddler_temp_fixed.har");
var tempDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "fiddler_output_" + System.Guid.NewGuid().ToString().Substring(0, 8));

// 清理旧文件
if(System.IO.File.Exists(tempHar)) System.IO.File.Delete(tempHar);
if(System.IO.File.Exists(tempHarFixed)) System.IO.File.Delete(tempHarFixed);
if(System.IO.Directory.Exists(tempDir)) System.IO.Directory.Delete(tempDir, true);

// 步骤 1:导出 HAR 文件
var oExportOptions = FiddlerObject.createDictionary();
oExportOptions.Add("Filename", tempHar);
FiddlerApplication.DoExport("HTTPArchive v1.2", oSessions, oExportOptions, null);

if(!System.IO.File.Exists(tempHar)) {
MessageBox.Show("❌ 导出 HAR 文件失败", "错误");
return;
}

// 步骤 2:移除 BOM
RemoveBomFromFile(tempHar, tempHarFixed);

if(!System.IO.File.Exists(tempHarFixed)) {
MessageBox.Show("❌ 处理 HAR 文件失败", "错误");
System.IO.File.Delete(tempHar);
return;
}

// 步骤 3:创建输出目录
System.IO.Directory.CreateDirectory(tempDir);

// 🔑 步骤 4:直接调用 httpsnippet(使用系统 PATH)
var args = "httpsnippet "" + tempHarFixed + "" -t python -c " + client + " -o "" + tempDir + """;

var process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe"; // 使用 cmd.exe
process.StartInfo.Arguments = "/c " + args; // /c 参数执行命令后退出
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();

var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();

process.WaitForExit();
process.Dispose();

// 步骤 5:查找生成的 Python 文件
var generatedFiles = System.IO.Directory.GetFiles(tempDir, "*.py");

if(generatedFiles.Length > 0) {
// 读取并删除
var code = System.IO.File.ReadAllText(generatedFiles[0]);
System.IO.File.Delete(generatedFiles[0]);
System.IO.Directory.Delete(tempDir, true);
System.IO.File.Delete(tempHar);
System.IO.File.Delete(tempHarFixed);

Clipboard.SetText(code);
MessageBox.Show("✅ Python 代码已生成并复制到剪贴板!\n\n客户端: " + client, "成功");
} else {
// 清理所有临时文件
if(System.IO.File.Exists(tempHar)) System.IO.File.Delete(tempHar);
if(System.IO.File.Exists(tempHarFixed)) System.IO.File.Delete(tempHarFixed);
if(System.IO.Directory.Exists(tempDir)) System.IO.Directory.Delete(tempDir, true);

MessageBox.Show("❌ 生成代码失败!\n\n错误信息:\n" + error, "错误");
}
}
// 🔑 关键函数:移除文件的 BOM
static function RemoveBomFromFile(sourceFile: String, targetFile: String) {
// 读取文件内容(File.ReadAllText 会自动处理 BOM)
var content = System.IO.File.ReadAllText(sourceFile, System.Text.Encoding.UTF8);

// 使用无 BOM 的 UTF8 编码保存
// new UTF8Encoding(false) 中的 false 表示不添加 BOM
var utf8WithoutBom = new System.Text.UTF8Encoding(false);

System.IO.File.WriteAllText(targetFile, content, utf8WithoutBom);
}
// ==================== 结束 ====================`

图片