diff --git a/app.py b/app.py index 4761568..be7fd4f 100644 --- a/app.py +++ b/app.py @@ -318,13 +318,25 @@ async def capture_with_playwright( await stealth_async(page) try: - await page.goto(url, wait_until="networkidle", timeout=30000) - except: await page.goto(url, wait_until="domcontentloaded", timeout=30000) + except Exception as e: + # 如果 domcontentloaded 超时,尝试 commit + try: + await page.goto(url, wait_until="commit", timeout=30000) + except: + pass + # 固定等待时间(用于验证、加载等过程) if wait_time > 0: await page.wait_for_timeout(wait_time) + # 等待页面基本稳定 + try: + await page.wait_for_load_state("networkidle", timeout=5000) + except: + # networkidle 超时没关系,继续执行 + pass + if scroll_times > 0: for i in range(scroll_times): await page.evaluate("window.scrollBy(0, 800)") diff --git a/templates/index.html b/templates/index.html index de67b77..680b78d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -295,20 +295,21 @@
- +
- + + + 某些网站需要较长验证过程,可设置为 10000-30000 +
+
+
-
- - -
@@ -350,16 +351,23 @@
-

📚 API 文档

-

POST /api/capture

-
{
+            

📚 使用说明

+

重要提示:

+
    +
  • ⏱️ 页面加载等待:某些网站需要验证过程(如 Cloudflare),请设置较长时间(10000-30000ms)
  • +
  • 🔄 滚动次数:用于加载动态内容(如微博、推特等),建议 3-5 次
  • +
  • 🎯 全页截图:滚动加载后建议开启此选项
  • +
+

API 调用:

+
POST /api/capture
+{
   "url": "https://example.com",
   "action": "screenshot",  // 或 "html"
-  "scroll_times": 3,
-  "scroll_delay": 1000,
-  "full_page": true,
-  "viewport": {"width": 1920, "height": 1080},
-  "wait_time": 2000
+  "wait_time": 15000,     // 重要!验证网站需设置较长等待
+  "scroll_times": 3,      // 可选:加载动态内容
+  "scroll_delay": 1000,  // 可选:滚动间隔
+  "full_page": true,     // 可选:全页截图
+  "backend": "playwright" // 可选:playwright 或 agent-browser
 }