跳转到主要内容
获取令牌时遇到问题吗
联系支持

reCAPTCHA v3

注意!

任务通过我们的自有代理服务器执行。您无需为代理支付额外费用 —— 它们的使用已包含在价格中。

本节介绍了用于解决 Google reCAPTCHA v3 的任务说明。

reCAPTCHA v3 完全在后台运行,不需要用户执行任何操作。系统会分析页面访问者的行为和技术信号,并为每个请求生成风险评分。网站会根据这些数据,通过信任评分来决定是否允许该操作,该评分通常位于 0.10.9 的范围内。

在创建任务时,建议传递两个参数:pageActionminScore

请求参数

type<string>required

RecaptchaV3TaskProxyless


websiteURL<string>required

带有 Google ReCaptcha 的网页地址。


websiteKey<string>required

目标页面上的 ReCaptcha v3 标识密钥。 https://www.google.com/recaptcha/api.js?render=THIS_ONE

大致格式如下:6Le0xVgUAAAAAIt20XEB4rVhYOODgTl00d8juDob


isEnterprise<boolean>optional

reCAPTCHA 版本。支持的值:true / false(也允许使用整数类型的 1 / 0)。

如果需要解决 Enterprise 版本的 reCAPTCHA,请指定 true——在这种情况下,任务将按照 RecaptchaV3EnterpriseTask 的方式处理。


minScore<double>optional

可取值范围为 0.1 到 0.9


pageAction<string>optional

ReCaptcha 小部件传递给 Google 的 action 参数值,网站所有者在服务器端后续验证时可以看到该值。如果该值不同于默认值 verify,请指定此参数。

html 示例:
grecaptcha.execute('site_key', {action:'login_test'}).

创建任务方法

POST
https://api.capmonster.cloud/createTask

请求示例

{
"clientKey": "API_KEY",
"task": {
"type": "RecaptchaV3TaskProxyless",
"websiteURL": "https://yourwebsite.com/page-with-recaptcha",
"websiteKey": "your-website-key",
"isEnterprise": false,
"minScore": 0.7,
"pageAction": "your-verify"
}
}

响应示例

{
"errorId":0,
"taskId":407533072
}

获取任务结果方法

警告!

在某些网站上,确保 UserAgent 与解决验证码时使用的 UserAgent 相匹配非常重要。因此,如果 CapMonster Cloud 在返回令牌的同时提供了 UserAgent,请始终在提交表单或在目标页面确认解决方案时使用该 UserAgent。

使用 getTaskResult 请求获取 ReCaptcha3 的答案。根据服务负载情况,您将在 10 到 30 秒内收到响应。

POST
https://api.capmonster.cloud/getTaskResult

请求示例

{
"clientKey":"API_KEY",
"taskId": 407533072
}

响应示例

{
"errorId": 0,
"status": "ready",
"solution": {
"gRecaptchaResponse": "3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3"
}
}

对于某些网站,响应可能如下所示。提交解决方案时,请确保使用响应中提供的 UserAgent,即使它与您当前使用的浏览器或脚本不同。

{
"errorId": 0,
"status": "ready",
"solution": {
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
"gRecaptchaResponse": "0cAFcWeA5Y3...hF8UWA",
"cookies": {
"nocookies": "true"
}
}
}

属性类型描述
gRecaptchaResponseString需要填入 ReCaptcha3 表单中 <textarea id="g-recaptcha-response" ></textarea> 的哈希值。长度为 500 到 2190 字节。

如何查找任务创建所需的所有参数

手动方式

  1. 在浏览器中打开显示验证码的网站。
  2. 右键单击验证码元素并选择 Inspect

websiteKey

公开站点密钥(sitekey),通常可以在包含的脚本中找到:

Elements 中:

elements

Network 选项卡中:

network

pageAction

传递给 grecaptcha.execute() 的操作名称。例如:

action

自动方法

为了自动化获取所需参数,可以通过 浏览器(普通模式或 headless 模式,例如使用 Playwright)进行提取,或直接从 HTTP 请求中获取。由于动态参数的有效时间较短,建议在获取后尽快使用。

重要

所提供的代码片段仅作为获取必要参数的基础示例。具体实现方式取决于包含验证码的网站、本身的页面结构,以及所使用的 HTML 元素和选择器。

显示代码(浏览器中)
(() => {
const originalGrecaptcha = window.grecaptcha;

if (!originalGrecaptcha || !originalGrecaptcha.execute) {
console.warn("未找到grecaptcha.execute,请等待加载完成");
return;
}

window.__extractedParams = null;

window.grecaptcha = {
...originalGrecaptcha,
execute: function(sitekey, config) {
console.log("已捕获!");
console.log("sitekey:", sitekey);
console.log("action:", config?.action);
window.__extractedParams = {
sitekey,
action: config?.action
};

return originalGrecaptcha.execute(sitekey, config);
},
ready: originalGrecaptcha.ready
};

console.log("grecaptcha.execute已被封装。点击按钮-参数将被捕获");
})();
显示代码(Node.js)
import { chromium } from "playwright";

(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();

const jsContents = [];

page.on("response", async (response) => {
try {
const url = response.url();
const ct = response.headers()["content-type"] || "";
if (ct.includes("javascript") || url.endsWith(".js")) {
const text = await response.text();
jsContents.push(text);
}
} catch (e) {}
});

const targetUrl = "https://yourwebsite.com/page-with-recaptcha";
await page.goto(targetUrl, { timeout: 60000 });
await page.waitForTimeout(3000);

const inlineScripts = await page.$$eval("script:not([src])", (scripts) =>
scripts.map((s) => s.textContent)
);
jsContents.push(...inlineScripts);

const executeRegex =
/grecaptcha\.execute\(\s*['"]
(?<sitekey>[^'"]+)['"]\s*,\s*\{[^}]*action\s*:\s*['"](?<action>[^'"]+)['"]/i;

let foundSitekey = null;
let foundAction = null;

for (const js of jsContents) {
const match = js.match(executeRegex);
if (match && match.groups) {
foundSitekey = match.groups.sitekey;
foundAction = match.groups.action;
break;
}
}

console.log({
sitekey: foundSitekey,
action: foundAction,
});

await browser.close();
})();

使用 SDK 库

显示代码(用于浏览器)
// https://github.com/ZennoLab/capmonstercloud-client-js

import {
CapMonsterCloudClientFactory,
ClientOptions,
RecaptchaV3ProxylessRequest
} from '@zennolab_com/capmonstercloud-client';

document.addEventListener('DOMContentLoaded', async () => {

const cmcClient = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: 'YOUR_API_KEY' }) // 输入您的 CapMonster Cloud API 密钥
);

// 如有必要,可以检查余额
const balance = await cmcClient.getBalance();
console.log('Balance:', balance);

const recaptchaV3Request = new RecaptchaV3ProxylessRequest({
websiteURL: 'https://yourwebsite.com/page-with-recaptcha', // 包含验证码的页面 URL
websiteKey: 'your-website-key',
minScore: 0.7,
pageAction: 'your-verify',
});

const solution = await cmcClient.Solve(recaptchaV3Request);
console.log('Solution:', solution);

});
显示代码 (Node.js)
// https://github.com/ZennoLab/capmonstercloud-client-js

import { CapMonsterCloudClientFactory, ClientOptions, RecaptchaV3ProxylessRequest } from '@zennolab_com/capmonstercloud-client';

const API_KEY = "YOUR_API_KEY"; // 输入您的 CapMonster Cloud API 密钥

async function solveRecaptchaV3() {
const cmcClient = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: API_KEY })
);

// 如有必要,可以检查余额
const balance = await cmcClient.getBalance();
console.log("Balance:", balance);

const recaptchaV3Request = new RecaptchaV3ProxylessRequest({
websiteURL: "https://yourwebsite.com/page-with-recaptcha",
websiteKey: "your-website-key",
minScore: 0.7,
pageAction: "your-verify",
});

const solution = await cmcClient.Solve(recaptchaV3Request);
console.log("Solution:", solution);
}

solveRecaptchaV3().catch(console.error);
更多相关内容,请访问我们的博客