MadKangYu/tiered-scraper

GitHub: MadKangYu/tiered-scraper

六层自动升级网页爬虫,结合多种浏览器伪装技术和 AI 视觉验证码求解器,可绕过 Cloudflare、DataDome、Turnstile 等主流反机器人系统。

Stars: 0 | Forks: 0

# 分层 Scraper 6 层自动升级网页爬虫,配备 AI 视觉验证码 (CAPTCHA) 求解器。 自动逐步升级使用更强大的爬取策略,直到成功为止。可绕过 Cloudflare、DataDome、Turnstile 以及其他反机器人系统。 ## 工作原理 ``` Request │ ├─ Tier 1: httpx → Plain HTTP (fastest, ~0.5s) ├─ Tier 2: StealthyFetcher → TLS fingerprint spoofing ├─ Tier 3: patchright → Playwright with CDP leak patches ├─ Tier 4: nodriver → Direct Chrome communication (no CDP traces) ├─ Tier 5: camoufox → Firefox modified at C++ level └─ Tier 6: Vision Solver → Screenshot → AI Vision → coordinate click ``` 每一层按顺序尝试。如果检测到质询页面,它会自动升级到下一层。不可用的层(缺少依赖项)将被跳过。 ## 测试结果 | 站点 | 防护 | 绕过层级 | 结果 | |------|-----------|-------------|--------| | httpbin.org | 无 | 第 1 层 | PASS | | nowsecure.nl | Cloudflare | 第 5 层 | PASS | | G2.com | Cloudflare + DataDome | 第 5 层 | PASS | | Indeed.com | CF Enterprise | 第 5 层 | PASS | | Crunchbase.com | Cloudflare | 第 5 层 | PASS | | Discord.com | Cloudflare | 第 5 层 | PASS | ## 安装 ``` # Minimal(仅 Tier 1) pip install tiered-scraper # 包含所有 Tier pip install tiered-scraper[all] # 单独 Tier pip install tiered-scraper[stealth] # + Tier 2 pip install tiered-scraper[browser] # + Tier 3 pip install tiered-scraper[nodriver] # + Tier 4 pip install tiered-scraper[camoufox] # + Tier 5 pip install tiered-scraper[vision] # + Tier 6 ``` ## 快速开始 ``` import asyncio from tiered_scraper import TieredScraper async def main(): scraper = TieredScraper() # Auto-escalation: tries Tier 1→2→3→4→5→6 until success html = await scraper.fetch("https://example.com") print(f"Got {len(html)} bytes") # Force a specific tier html = await scraper.fetch("https://cf-protected.com", tier=5) # Check stats print(scraper.stats) asyncio.run(main()) ``` ## 配置 ``` scraper = TieredScraper( timeout=30, # Per-tier timeout (seconds) proxy="socks5://user:pass@host:port", # Proxy for all tiers anthropic_api_key="sk-ant-...", # For Tier 6 Vision Solver ) ``` ## 层级详情 ### 第 1 层: httpx - **速度**: ~0.5s | **成本**: 免费 - 纯 HTTP 请求。无 JS 渲染。 - 适用于: RSS 订阅、简单 HTML、API。 ### 第 2 层: StealthyFetcher - **速度**: ~2s | **成本**: 免费 - 通过 [scrapling](https://github.com/D4Vinci/Scrapling) 进行 TLS 指纹伪装。 - 适用于: 检查 TLS 握手模式的站点。 ### 第 3 层: patchright - **速度**: ~3s | **成本**: 免费 - [Patchright](https://github.com/AjitSinghKaler/patchright) — 带有 CDP 泄露补丁的 Playwright。 - 适用于: JS 渲染的 SPA、基础机器人检测。 ### 第 4 层: nodriver - **速度**: ~5s | **成本**: 免费 - [Nodriver](https://github.com/niceno/nodriver) — 无 CDP 痕迹的直接 Chrome 通信。 - 适用于: 检测 `Runtime.Enable` CDP 调用的站点。 - **Cloudflare 绕过率**: ~83% (基准测试)。 ### 第 5 层: camoufox - **速度**: ~8s | **成本**: 免费 - [Camoufox](https://github.com/daijro/camoufox) — 在 C++ 二进制级别修改的 Firefox。 - 适用于: **Cloudflare, DataDome, Akamai, PerimeterX**。 - **检测分数**: 在主要测试套件中为 0%。 ### 第 6 层: Vision Solver - **速度**: ~15s | **成本**: API 调用 (~$0.001/次) - 对页面截图 → Claude Vision API 识别验证码 (CAPTCHA) 位置 → 使用类人鼠标移动进行点击。 - **原理**: 使用实际屏幕坐标 (screenX/Y 为百位数),而非 CDP iframe 坐标 (< 100)。Cloudflare Turnstile 无法将其与人类点击区分开来。 - 适用于: Turnstile, reCAPTCHA, hCaptcha 以及任何视觉质询。 - 需求: `ANTHROPIC_API_KEY` 环境变量。 ## 质询检测 爬虫通过查找以下模式自动检测质询页面: - "Checking if the site connection is secure" - "Verify you are human" - Cloudflare ray IDs - Turnstile iframe 标记 如果在获取后检测到质询,爬虫会升级到下一层,而不是返回被阻止的内容。 ## 为什么存在每一层 | 防御机制 | T1 | T2 | T3 | T4 | T5 | T6 | |---------|----|----|----|----|----|----| | 需要 JS 渲染 | - | - | ✓ | ✓ | ✓ | ✓ | | TLS 指纹识别 | - | ✓ | - | ✓ | ✓ | ✓ | | CDP 检测 | - | - | ✓ | ✓ | ✓ | ✓ | | navigator.webdriver | - | - | ✓ | ✓ | ✓ | ✓ | | Cloudflare 质询 | - | - | - | - | ✓ | ✓ | | DataDome | - | - | - | - | ✓ | ✓ | | Turnstile 鼠标坐标 | - | - | - | - | ? | ✓ | | 针对客户的 ML | - | - | - | - | ? | ✓ | | 视觉验证码 (CAPTCHA) | - | - | - | - | - | ✓ | ## 状态管理 内置用于跟踪已见 URL 和持久化状态的工具: ``` from tiered_scraper import load_state, save_state, is_seen, mark_seen state = load_state("./scraper-state.json") if not is_seen(state, url): html = await scraper.fetch(url) mark_seen(state, url) save_state("./scraper-state.json", state) # Atomic write ``` ## 许可证 MIT
标签:AI视觉求解器, Bot检测规避, Camoufox, CDP补丁, Cloudflare绕过, DataDome绕过, DNS 解析, IP 地址批量处理, Nodriver, Patchright, Playwright, Python, TLS指纹伪造, Turnstile绕过, 反反爬虫, 无后门, 浏览器指纹伪装, 特征检测, 自动化数据采集, 自动升级策略, 计算机取证, 足迹分析, 运行时操纵, 逆向工具, 验证码识别