From fc43e6e80623986517463a025b188e0f0b02bd1b Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Sun, 5 Jul 2026 01:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=89=E5=BE=85=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E6=94=AF=E6=8C=81=E9=95=BF=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改进: - 页面加载等待时间上限提高到 60秒 - 添加等待 networkidle 状态逻辑 - 前端界面增加等待设置说明 - 提示用户针对验证网站设置 10-30秒等待 使用场景: - Cloudflare 等验证网站 - 复杂加载过程网站 - 需要用户确认的页面 --- app.py | 16 ++++++++++++++-- templates/index.html | 36 ++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 16 deletions(-) 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
 }