当前位置: 首页 > article >正文

如何绕过 reCAPTCHA V2/V3:Python、Selenium 与其他工具的实战指南

前言

验证码(CAPTCHA)技术已经存在多年,尽管它的有效性一直备受争议,但许多网站仍然依赖它来保护资源。特别是 Google 推出的 reCAPTCHA 系列,一直是验证码领域的领跑者。本文将探讨如何绕过 reCAPTCHA V2 和 V3,并提供实用的代码示例。

详情请见:解决验证码recaptcha、cloudflare、incapsula


1. 什么是 reCAPTCHA?

reCAPTCHA 是 Google 推出的验证码技术,旨在通过验证用户行为来区分人类与机器人。它目前有三个主要版本:

  • reCAPTCHA V1:基于扭曲文本的传统验证码(已淘汰)。
  • reCAPTCHA V2:用户需要点击复选框或完成图片任务。
  • reCAPTCHA V3:无感验证,通过用户行为生成风险评分。

2. 绕过 reCAPTCHA 的方法

2.1 绕过 reCAPTCHA V2

reCAPTCHA V2 的工作原理

reCAPTCHA V2 主要通过以下两种形式验证用户:

  1. 复选框验证:“我不是机器人”按钮,点击即可通过。
  2. 图片任务:用户需要从图片中选择特定对象(如交通信号灯、斑马线等)。

尽管 reCAPTCHA V2 提升了用户体验,但它仍然存在被自动化工具绕过的可能。

绕过方法

以下是一些常用的绕过方法:

  1. 使用 nocaptcha服务

nocaptcha 是一个流行的验证码解决服务,支持多种编程语言。以下是 Python 示例代码:

import requests
import time

API_KEY = 'Your_API_2Captcha_key'

def solve_recaptcha_v2(site_key, url):
    payload = {
        'key': API_KEY,
        'method': 'userrecaptcha',
        'googlekey': site_key,
        'pageurl': url,
        'json': 1
    }
    response = requests.post('https://.com/in.php', data=payload)
    result = response.json()
    
    if result['status'] != 1:
        raise Exception(f"Error when sending captcha: {result['request']}")
    
    captcha_id = result['request']
    while True:
        time.sleep(5)
        response = requests.get(f"https://.com/res.php?key={API_KEY}&action=get&id={captcha_id}&json=1")
        result = response.json()
        if result['status'] == 1:
            return result['request']
        elif result['request'] == 'CAPCHA_NOT_READY':
            continue
        else:
            raise Exception(f"Error while solving captcha: {result['request']}")

site_key = 'your_site_key_v2'
url = 'https://example.com'
token = solve_recaptcha_v2(site_key, url)
print(f"Received token: {token}")
  1. Selenium 自动化

Selenium 是一个强大的浏览器自动化工具,可以模拟用户行为完成验证。


2.2 绕过 reCAPTCHA V3

reCAPTCHA V3 的工作原理

与 V2 不同,reCAPTCHA V3 是无感验证,系统会根据用户行为生成 0.1 到 1.0 的风险评分。分数越高,用户越可能是真人。

绕过方法

同样支持 reCAPTCHA V3。以下是 Python 示例:

def solve_recaptcha_v3(site_key, url, action='verify', min_score=0.3):
    payload = {
        'key': API_KEY,
        'method': 'userrecaptcha',
        'googlekey': site_key,
        'pageurl': url,
        'version': 'v3',
        'action': action,
        'min_score': min_score,
        'json': 1
    }
    response = requests.post('https://2captcha.com/in.php', data=payload)
    result = response.json()
    
    if result['status'] != 1:
        raise Exception(f"Error when sending captcha: {result['request']}")
    
    captcha_id = result['request']
    while True:
        time.sleep(5)
        response = requests.get(f"https://2captcha.com/res.php?key={API_KEY}&action=get&id={captcha_id}&json=1")
        result = response.json()
        if result['status'] == 1:
            return result['request']
        elif result['request'] == 'CAPCHA_NOT_READY':
            continue
        else:
            raise Exception(f"Error while solving captcha: {result['request']}")

site_key = 'your_site_key_v3'
url = 'https://example.com'
token = solve_recaptcha_v3(site_key, url)
print(f"Received token: {token}")
  1. 模拟用户行为

通过 Selenium 或 Puppeteer 模拟用户行为,避免触发高风险评分。

详情请见:解决验证码recaptcha、cloudflare、incapsula


3. 其他语言的实现

JavaScript

在 Node.js 中,可以使用以下模块:

  • 2captcha:官方模块,支持 TypeScript。
  • captcha-solver:集成 Puppeteer,提供开箱即用的解决方案。

以下是 Node.js 示例代码:

const axios = require('axios');
const sleep = require('util').promisify(setTimeout);

const API_KEY = 'YOUR_API_KEY_2CAPTCHA';

async function solveReCaptchaV2(siteKey, pageUrl) {
    const sendCaptchaResponse = await axios.post('http://2captcha.com/in.php', null, {
        params: {
            key: API_KEY,
            method: 'userrecaptcha',
            googlekey: siteKey,
            pageurl: pageUrl,
            json: 1
        }
    });
    const requestId = sendCaptchaResponse.data.request;

    while (true) {
        await sleep(5000);
        const getResultResponse = await axios.get('http://2captcha.com/res.php', {
            params: {
                key: API_KEY,
                action: 'get',
                id: requestId,
                json: 1
            }
        });

        if (getResultResponse.data.status === 1) {
            return getResultResponse.data.request;
        } else if (getResultResponse.data.request === 'CAPCHA_NOT_READY') {
            continue;
        } else {
            throw new Error(`Error while solving captcha: ${getResultResponse.data.request}`);
        }
    }
}

(async () => {
    const siteKey = 'YOUR_SITE_KEY';
    const pageUrl = 'https://example.com';
    const token = await solveReCaptchaV2(siteKey, pageUrl);
    console.log(`Received token: ${token}`);
})();

详情请见:解决验证码recaptcha、cloudflare、incapsula


http://www.kler.cn/a/583154.html

相关文章:

  • 智慧城市时空基础设施建设与应用实践
  • MySQL——基础知识
  • Tensorflow 2.0 GPU的使用与限制使用率及虚拟多GPU
  • 网络爬虫-2:正则化
  • 大语言模型-01-语言模型发展历程-03-预训练语言模型到大语言模型
  • 两会期间的科技强音:DeepSeek技术引领人工智能新篇章
  • Node.js:快速启动你的第一个Web服务器
  • 无人机快速发展,无人机反制如何应对?
  • 第44天:WEB攻防-PHP应用SQL盲注布尔回显延时判断报错处理增删改查方式
  • 【写作模板】JosieBook的写作模板
  • 使用CPR库编写的爬虫程序
  • 大语言模型微调和大语言模型应用区别
  • 机器学习常见激活函数
  • vscode出现:No module named ‘requests‘ 问题的解决方法
  • ubuntu 在VirtualBox 打不开终端
  • Oracle RAC环境下自动清理归档日志实战指南
  • Java静态变量与PHP静态变量的对比
  • HTMLCSS绘制三角形
  • 数据结构-队列(详解)
  • 软件安全分析与应用之综合安全应用 (三)