"""临时:从已抓到的 packets.jsonl 里提取导出链路报文(紧凑版,用完即删)。""" import json import os import sys if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "capture", "20261106-093603") OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "_dump_export.txt") WANT = ("exportNew", "download/polling", "download/downLoadList", "download/look", "download/read", "download/downLoad/") seen = {} order = [] for raw in open(os.path.join(ROOT, "packets.jsonl"), encoding="utf-8"): rec = json.loads(raw) path = rec["path"] if not any(k in path for k in WANT): continue key = (rec["method"], path if "download" not in path else path.split("/read/")[0].split("/downLoad/")[0]) if key in seen: continue seen[key] = rec order.append(key) lines = [] for key in order: rec = seen[key] lines.append("-" * 90) lines.append(f"{rec['method']} {rec['url']}") lines.append(f" POST: {(rec['postData'] or '')[:900]}") body = rec.get("body") or "" lines.append(f" RESP({rec['size']}B) ct={rec['contentType']} bin={rec['binaryFile']}") lines.append(f" {body[:900]}") text = "\n".join(lines) with open(OUT, "w", encoding="utf-8") as f: f.write(text) print(f"wrote {len(text)} chars, {len(order)} unique")