使用Cloudscrape+Anticaptcha无法绕过Cloudflare v2验证码求助
问题解决方案
报错原因
你遇到的报错明确说明:cloudscrape的开源免费版不支持Cloudflare v2验证码的自动绕过,即便配置了Anticaptcha也无法触发对应处理逻辑,这是工具本身的功能限制。
可行解决办法
1. 替换为真实浏览器模拟工具(推荐)
既然PC端无痕窗口能正常绕过验证,说明真实浏览器环境可通过检测,用Playwright或Selenium模拟真实浏览器行为,搭配代理和Anticaptcha即可复刻该场景:
- 示例(Playwright + Anticaptcha):
from playwright.sync_api import sync_playwright import anticaptchaofficial.recaptchav2proxyless as anticaptcha import queue def worker(q, p): while True: try: ip, port, user, passwd = p.get(timeout=1) proxy_config = { "server": f"http://{ip}:{port}", "username": user, "password": passwd } with sync_playwright() as pw: browser = pw.chromium.launch( headless=False, # 调试时可改为False,上线后切换为True proxy=proxy_config ) page = browser.new_page(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36") page.goto("https://LINK_with_cloudflare/") # 检测并处理Cloudflare v2验证码 if page.locator('[data-sitekey]').is_visible(): site_key = page.locator('[data-sitekey]').get_attribute('data-sitekey') solver = anticaptcha.solver() solver.set_key("ANTICAPTCHA_KEY") token = solver.solve_and_return_solution(site_key, "https://LINK_with_cloudflare/") if token != 0: page.evaluate(f'document.getElementById("g-recaptcha-response").innerHTML="{token}";') page.click('button[type="submit"]') # 等待页面加载完成后获取内容 page.wait_for_load_state("networkidle") print(page.content()) browser.close() except queue.Empty: break
2. 修正cloudscrape配置(尝试性修复,不保证生效)
如果坚持使用cloudscrape,先修正几个配置错误:
- 修复请求头格式:
sec-ch-ua的引号格式混乱,正确写法如下:headers = { 'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36', } - 调整
no_proxy参数:设置为false,确保Anticaptcha请求和爬虫请求使用同一代理IP,避免Cloudflare检测到IP不一致:scraper = cloudscraper.create_scraper( interpreter='nodejs', captcha={ 'provider': 'anticaptcha', 'api_key': 'ANTICAPTCHA_KEY', 'no_proxy': 'false' } ) - 确认代理格式正确:
proxy变量需是符合requests要求的字典,例如:proxy = { "http": f"http://{user}:{passwd}@{ip}:{port}", "https": f"http://{user}:{passwd}@{ip}:{port}" }
3. 升级到cloudscrape付费版
如果上述方法均无效,可选择cloudscrape的付费版本,其官方明确说明付费版支持Cloudflare v2验证码的自动处理。
内容的提问来源于stack exchange,提问作者Mopkon
相关产品推荐
相关产品推荐

