"""Capture gongzicp API calls via Playwright.""" from __future__ import annotations import json from playwright.sync_api import sync_playwright from pixiv_app.core.playwright_runtime import configure_playwright_runtime_env, preferred_chromium_executable def main() -> None: configure_playwright_runtime_env() calls: list[dict] = [] with sync_playwright() as p: browser = p.chromium.launch( headless=True, executable_path=preferred_chromium_executable(), ) context = browser.new_context( user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0", ) page = context.new_page() def on_request(request): url = request.url if "gongzicp" in url and ("apiv2" in url or "webapi" in url): post = request.post_data or "" calls.append( { "url": url, "method": request.method, "post": post[:2000], } ) page.on("request", on_request) page.goto("https://www.gongzicp.com/novel-429598.html", wait_until="networkidle", timeout=120000) page.wait_for_timeout(5000) browser.close() print(json.dumps(calls, ensure_ascii=False, indent=2)) if __name__ == "__main__": main()