优化等待设置,支持长时间验证过程
改进: - 页面加载等待时间上限提高到 60秒 - 添加等待 networkidle 状态逻辑 - 前端界面增加等待设置说明 - 提示用户针对验证网站设置 10-30秒等待 使用场景: - Cloudflare 等验证网站 - 复杂加载过程网站 - 需要用户确认的页面
This commit is contained in:
16
app.py
16
app.py
@@ -318,13 +318,25 @@ async def capture_with_playwright(
|
|||||||
await stealth_async(page)
|
await stealth_async(page)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await page.goto(url, wait_until="networkidle", timeout=30000)
|
|
||||||
except:
|
|
||||||
await page.goto(url, wait_until="domcontentloaded", timeout=30000)
|
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:
|
if wait_time > 0:
|
||||||
await page.wait_for_timeout(wait_time)
|
await page.wait_for_timeout(wait_time)
|
||||||
|
|
||||||
|
# 等待页面基本稳定
|
||||||
|
try:
|
||||||
|
await page.wait_for_load_state("networkidle", timeout=5000)
|
||||||
|
except:
|
||||||
|
# networkidle 超时没关系,继续执行
|
||||||
|
pass
|
||||||
|
|
||||||
if scroll_times > 0:
|
if scroll_times > 0:
|
||||||
for i in range(scroll_times):
|
for i in range(scroll_times):
|
||||||
await page.evaluate("window.scrollBy(0, 800)")
|
await page.evaluate("window.scrollBy(0, 800)")
|
||||||
|
|||||||
@@ -295,20 +295,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>滚动设置(用于加载动态内容)</label>
|
<label>等待设置(重要!)</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div>
|
<div>
|
||||||
<label for="scrollTimes">滚动次数</label>
|
<label for="waitTime">页面加载等待(ms) ⏱️</label>
|
||||||
|
<input type="number" id="waitTime" value="2000" min="0" max="60000" step="500">
|
||||||
|
<small style="color: #666; display: block; margin-top: 4px;">某些网站需要较长验证过程,可设置为 10000-30000</small>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="scrollTimes">滚动次数(可选)</label>
|
||||||
<input type="number" id="scrollTimes" value="0" min="0" max="20">
|
<input type="number" id="scrollTimes" value="0" min="0" max="20">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="scrollDelay">滚动间隔(ms)</label>
|
<label for="scrollDelay">滚动间隔(ms)</label>
|
||||||
<input type="number" id="scrollDelay" value="1000" min="500" max="5000" step="100">
|
<input type="number" id="scrollDelay" value="1000" min="500" max="5000" step="100">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<label for="waitTime">页面加载等待(ms)</label>
|
|
||||||
<input type="number" id="waitTime" value="2000" min="0" max="10000" step="500">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -350,16 +351,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card api-docs">
|
<div class="card api-docs">
|
||||||
<h3>📚 API 文档</h3>
|
<h3>📚 使用说明</h3>
|
||||||
<p>POST /api/capture</p>
|
<p><strong>重要提示:</strong></p>
|
||||||
<pre><code>{
|
<ul style="margin: 10px 0; line-height: 1.8;">
|
||||||
|
<li>⏱️ <strong>页面加载等待</strong>:某些网站需要验证过程(如 Cloudflare),请设置较长时间(10000-30000ms)</li>
|
||||||
|
<li>🔄 <strong>滚动次数</strong>:用于加载动态内容(如微博、推特等),建议 3-5 次</li>
|
||||||
|
<li>🎯 <strong>全页截图</strong>:滚动加载后建议开启此选项</li>
|
||||||
|
</ul>
|
||||||
|
<p style="margin-top: 15px;"><strong>API 调用:</strong></p>
|
||||||
|
<pre><code>POST /api/capture
|
||||||
|
{
|
||||||
"url": "https://example.com",
|
"url": "https://example.com",
|
||||||
"action": "screenshot", // 或 "html"
|
"action": "screenshot", // 或 "html"
|
||||||
"scroll_times": 3,
|
"wait_time": 15000, // 重要!验证网站需设置较长等待
|
||||||
"scroll_delay": 1000,
|
"scroll_times": 3, // 可选:加载动态内容
|
||||||
"full_page": true,
|
"scroll_delay": 1000, // 可选:滚动间隔
|
||||||
"viewport": {"width": 1920, "height": 1080},
|
"full_page": true, // 可选:全页截图
|
||||||
"wait_time": 2000
|
"backend": "playwright" // 可选:playwright 或 agent-browser
|
||||||
}</code></pre>
|
}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user