From de829e970cf427ff693a72a4402225c2f628d361 Mon Sep 17 00:00:00 2001 From: theluyuan <1162963624@qq.com> Date: Thu, 26 Feb 2026 09:21:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20nodriver=20=E5=85=BC=E5=AE=B9=20-=20?= =?UTF-8?q?=E7=94=A8=20el[value]/get=5Fjs=5Fattributes=20=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20get=5Fattribute=EF=BC=8Cbrowser.stop()=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=20await?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- main.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 232fbd1..dda4c60 100644 --- a/main.py +++ b/main.py @@ -14,18 +14,24 @@ from cookies_loader import ( inject_netscape_cookies, ) -TARGET_URL = "https://dash.cloudflare.com/sign-up" +TARGET_URL = "https://audiences.me/torrents.php" async def get_search_btn_value(page): """获取 #search_btn 的 value,用于判断是否需要验证。""" try: el = await page.query_selector("#search_btn") + print(f"el: {el}") if el is None: return None - raw = await el.get_attribute("value") + # nodriver Element 用 el["value"] 或 get_js_attributes 取属性,无 get_attribute + raw = el["value"] + if raw is None: + attrs = await el.get_js_attributes() + raw = attrs.get("value") if attrs else None return (raw or "").strip() - except Exception: + except Exception as e: + print(f"Exception: {e}") return None @@ -98,9 +104,10 @@ async def run_one_check(): # 进入页面后等待一下再判断 await page.sleep(2) val = await get_search_btn_value(page) - if val == "给我搜": + print(f"val: {val}") + if val and "给我搜" in val: # 不需要验证,直接结束本次检查 - await browser.stop() + browser.stop() return # 需要验证:等待 CF 自动通过后尝试点击 Turnstile @@ -111,9 +118,10 @@ async def run_one_check(): # 验证后等 10 秒看是否变为「给我搜」 await page.sleep(10) val_after = await get_search_btn_value(page) - if val_after == "给我搜": + print(f"val_after: {val_after}") + if val_after and "给我搜" in val_after: # 已通过,关闭浏览器,结束本次检查 - await browser.stop() + browser.stop() return # 仍未通过,刷新页面重新走验证