mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix: CloakBrowser 获取页面源码在 CF 质询页超时 (#6402)
This commit is contained in:
@@ -1118,6 +1118,7 @@ class PlaywrightHelper:
|
|||||||
:param headless: 是否无头模式
|
:param headless: 是否无头模式
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间
|
||||||
"""
|
"""
|
||||||
|
timeout = timeout or 60
|
||||||
source = None
|
source = None
|
||||||
# 如果配置为 FlareSolverr,则直接调用获取页面源码
|
# 如果配置为 FlareSolverr,则直接调用获取页面源码
|
||||||
if self.__browser_emulation() == "flaresolverr":
|
if self.__browser_emulation() == "flaresolverr":
|
||||||
@@ -1140,10 +1141,33 @@ class PlaywrightHelper:
|
|||||||
if cookies:
|
if cookies:
|
||||||
page.set_extra_http_headers({"cookie": cookies})
|
page.set_extra_http_headers({"cookie": cookies})
|
||||||
|
|
||||||
page.goto(url)
|
page.goto(url, wait_until="load", timeout=timeout * 1000)
|
||||||
page.wait_for_load_state("networkidle", timeout=timeout * 1000)
|
|
||||||
|
|
||||||
source = page.content()
|
# 修复: 部分站点(如 Cloudflare 质询页)会持续轮询请求,
|
||||||
|
# 导致 networkidle 永不触发而超时。改为等待页面加载完成后
|
||||||
|
# 轮询检查标题, 直到不再停留在质询/加载页。
|
||||||
|
challenge_titles = ("just a moment", "请稍候", "loading")
|
||||||
|
deadline = time.time() + timeout
|
||||||
|
while time.time() < deadline:
|
||||||
|
try:
|
||||||
|
current_title = (page.title() or "").strip().lower()
|
||||||
|
except Exception:
|
||||||
|
current_title = ""
|
||||||
|
if current_title and not any(
|
||||||
|
t in current_title for t in challenge_titles):
|
||||||
|
break
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
# 页面跳转中 content() 可能失败, 重试几次
|
||||||
|
source = None
|
||||||
|
for _attempt in range(5):
|
||||||
|
try:
|
||||||
|
source = page.content()
|
||||||
|
if source:
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
source = None
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取网页源码失败: {str(e)}")
|
logger.error(f"获取网页源码失败: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user