feat: 每30分钟定时执行检查

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-21 20:03:23 +08:00
parent ade54c0d32
commit 7fef29dd0a

19
main.py
View File

@@ -1,8 +1,10 @@
"""
使用 Nodriver 访问 Cloudflare 保护的 audiences.me/torrents.php
启动时从根目录 cookies.txt 加载 Cookie采用等待自动通过 + 选择器点击 Turnstile 过验证。
每 30 分钟执行一次检查。
"""
import asyncio
import nodriver as uc
from cookies_loader import (
get_cookies_path,
@@ -70,7 +72,11 @@ async def try_click_cf_turnstile(page):
pass
async def main():
INTERVAL_MINUTES = 30
async def run_one_check():
"""执行一次检查:打开浏览器、过 CF 验证,完成后关闭浏览器。"""
# 建议非无头模式以提高 CF 通过率
browser = await uc.start(headless=False)
path = get_cookies_path()
@@ -93,7 +99,7 @@ async def main():
await page.sleep(2)
val = await get_search_btn_value(page)
if val == "给我搜":
# 不需要验证,直接结束
# 不需要验证,直接结束本次检查
await browser.stop()
return
@@ -106,7 +112,7 @@ async def main():
await page.sleep(10)
val_after = await get_search_btn_value(page)
if val_after == "给我搜":
# 已通过,关闭程序
# 已通过,关闭浏览器,结束本次检查
await browser.stop()
return
@@ -114,5 +120,12 @@ async def main():
page = await browser.get(TARGET_URL)
async def main():
"""每 30 分钟执行一次检查,循环运行。"""
while True:
await run_one_check()
await asyncio.sleep(INTERVAL_MINUTES * 60)
if __name__ == "__main__":
uc.loop().run_until_complete(main())