Files
lookingWeb/refresh_cf_cookies.py
cat-shark 01827224d6 fix: 修复主程序卡死与下载器集成,新增真实数据测试
- LookingWebMain: 强制 IPv4 避免 IPv6 不可达挂起;requests 加超时防卡死
- get_seed_from_element_detail: 修复限流页崩溃与 favicon 误作来源 URL,改用 canonical/传入 URL
- QbittorrentDownloader: 修复 main() 中模块/类误用导致的 download_by_seed AttributeError;请求加超时
- MySqlService: 修复数据库不可达时 query/execute/close 的 None 崩溃,close 后置空 connection
- 新增 cf_session: Cloudflare 人机认证 cookie 管理 + 限流退避重试 + 自动弹浏览器刷新验证
- 新增 refresh_cf_cookies.py: 弹出浏览器手动验证并保存 cf_clearance
- tests/: 真实网络/数据库测试(get_page、seed_is_exist、cf_session)+ run_tests.py runner
- 清理无用脚本(final_test2/verify_replace/REPLACEMENT_INFO),.idea 与 cookie 文件入 .gitignore

注: test_qbittorrent_downloader.py 11 个用例为既有失败(mock 目标 session 为实例属性,与实现错配),未在本次范围
2026-08-30 12:24:26 +08:00

40 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
弹出真实浏览器,手动完成 Cloudflare 人机验证,保存 cf_clearance cookie
用法: python refresh_cf_cookies.py
流程:
1. 以有窗口(headed)模式弹出浏览器打开 freejavbt.com
2. 若页面出现 Cloudflare 人机认证("Verify you are human" / 复选框),
请在浏览器窗口中手动点击完成验证(多数情况 JS 挑战会自动通过)
3. 检测到 cf_clearance cookie 后,自动保存到 cf_cookies.json
4. 之后运行主程序(LookingWebMain.py)即可正常访问;主程序遇到限流时
也会自动调用本逻辑完成刷新
依赖: agent-browser CLI/usr/bin/agent-browserpi 环境自带)
"""
import sys
import cf_session
def main():
print("=" * 60)
print("Cloudflare 人机验证 cookie 刷新工具")
print("=" * 60)
print(f"[1/3] 正在弹出浏览器窗口: {cf_session.SITE_URL}")
print("[2/3] 请在浏览器中完成验证(若出现人机认证框请点击确认)...")
ok = cf_session.refresh_cookies()
if ok:
print(f"[3/3] 验证成功!cf_clearance 已保存到 {cf_session.COOKIE_FILE}")
print(" 现在运行主程序即可正常访问: python LookingWebMain.py")
else:
print("[x] 验证失败或超时,请重试")
sys.exit(1)
if __name__ == "__main__":
main()