RecaptchaV2EnterpriseTask
该对象包含用于解决Google reCAPTCHA Enterprise任务的数据。为了提供解决此类任务的通用性,我们已经再现了您计划完成的自动化任务所需的每一个环境因素。包括代理访问、浏览器的用户代理、Cookies(可选)。
这种类型的验证码与ReCaptcha v.2在视觉上没有区别,您可以通过使用开发者工具中的网络选项卡下的查询来查看验证码代码的差异,例如:
这种类型的验证码可能比普通的图片验证码解决时间稍长一些,但这个问题被我们在解决您的ReCaptcha2后发送给您的g-captcha-response值在接下来的60秒内有效这一事实所弥补。
如果代理通过IP授权,请务必将116.203.55.208添加到白名单中。
请求参数
- RecaptchaV2EnterpriseTaskProxyless (无代理)
- RecaptchaV2EnterpriseTask (使用代理)
type
<string>requiredRecaptchaV2EnterpriseTaskProxyless
websiteURL
<string>required包含Google ReCaptcha Enterprise的网页地址。
websiteKey
<string>requiredRecaptcha 网站密钥。<div class="g-recaptcha" data-sitekey="THIS_ONE"></div>
或 <iframe title="reCAPTCHA" src="...;k=6LdIFr0ZAAAAAO3vz0O0OQrtAefzdJcWQM2TMYQH&...
,其中 6LdIFr0ZAAAAAO3vz0O0OQrtAefzdJcWQM2TMYQH
即为 websiteKey
enterprisePayload
<string>optional某些reCAPTCHA Enterprise小部件的实现可能包含传递给“grecaptcha.enterprise.render”方法的附加参数。例如: <pre lang="js" ><code>grecaptcha.enterprise.render("some-div-id", {<br /> sitekey: "6Lc\_aCMTAAAAABx7u2N0D1XnVbI\_v6ZdbM6rYf16"<br/> theme: "dark"<br/> s: "2JvUXHNTnZl1Jb6WEvbDyB...ugQA"<br/>});</code></pre>
apiDomain
<string>optional加载 reCAPTCHA Enterprise 的域名地址。例如
如果不知道为什么需要参数,请勿使用。
userAgent
<string>optional用于模拟的浏览器用户代理。必须使用现代浏览器的签名,否则Google会要求您“更新浏览器”。
cookies
<string>optional我们在与目标页面或Google交互期间必须使用的附加Cookies。
格式: cookiename1=cookievalue1; cookiename2=cookievalue2
type
<string>requiredRecaptchaV2EnterpriseTask
websiteURL
<string>required包含Google ReCaptcha Enterprise的网页地址。
websiteKey
<string>requiredRecaptcha 网站密钥。<div class="g-recaptcha" data-sitekey="THIS_ONE"></div>
或 <iframe title="reCAPTCHA" src="...;k=6LdIFr0ZAAAAAO3vz0O0OQrtAefzdJcWQM2TMYQH&...
,其中 6LdIFr0ZAAAAAO3vz0O0OQrtAefzdJcWQM2TMYQH
即为 websiteKey
enterprisePayload
<string>optional某些reCAPTCHA Enterprise小部件的实现可能包含传递给“grecaptcha.enterprise.render”方法的附加参数。例如: <pre lang="js" ><code>grecaptcha.enterprise.render("some-div-id", {<br /> sitekey: "6Lc\_aCMTAAAAABx7u2N0D1XnVbI\_v6ZdbM6rYf16"<br/> theme: "dark"<br/> s: "2JvUXHNTnZl1Jb6WEvbDyB...ugQA"<br/>});</code></pre>
apiDomain
<string>optional加载 reCAPTCHA Enterprise 的域名地址。例如
如果不知道为什么需要参数,请勿使用。
userAgent
<string>optional用于模拟的浏览器用户代理。必须使用现代浏览器的签名,否则Google会要求您“更新浏览器”。
cookies
<string>optional我们在与目标页面或Google交互期间必须使用的附加Cookies。
格式: cookiename1=cookievalue1; cookiename2=cookievalue2
proxyType
<string>requiredhttp - 普通的http/https代理;
https - 仅在“http”不起作用时尝试此选项(某些自定义代理服务器需 要);
socks4 - socks4代理;
socks5 - socks5代理。
proxyAddress
<string>required代理IP地址 IPv4/IPv6。不允许使用:
- 主机名代替IP;
- 透明代理(客户端IP可见);
- 来自本地网络的代理。
proxyPort
<integer>required代理端口。
proxyLogin
<string>optional代理登录。
proxyPassword
<string>optional代理密码。
对于 enterprisePayload
- 在调用它之前,您需要用自己的函数替换 grecaptcha.enterprise.render
函数,并从其参数中获取值。该函数在加载脚本后存在,验证码通常立即渲染或基于页面事件渲染。如果验证码在客户端使用当前字段 s
渲染,那么令牌很可能不会被接受。
可以在没有 s
字段的情况下调用原始函数。
apiDomain
是托管用于与reCAPTCHA交互的API接口的域,用于验证用户是否通过验证码。
脚本
var __test_grc = undefined;
var __test_enterprise = undefined;
var __test_render = undefined;
var __test_render_widget = undefined;
var __test_render_args = undefined; // 这里将是调用render时使用的对象。
var __test_handler = {
get: function(target, name, receiver) {
if (name == 'enterprise') {
return __test_enterprise ? __test_enterprise : (__test_enterprise = new Proxy(target[name], __test_handler));
} else if (name == 'render') {
__test_render = target[name];
return (function(a, b) {
__test_render_args = b;
__test_render_widget = a;
return __test_render(a, {sitekey: b.sitekey}); });
} else {
return target[name];
}
}
};
Object.defineProperty(window, 'grecaptcha', {
enumerable: true,
configurable: false,
get: function() {
return __test_grc;
},
set: function(value) {
__test_grc = new Proxy(value, __test_handler);
}
});
创建任务方法
- RecaptchaV2EnterpriseTaskProxyless (无代理)
- RecaptchaV2EnterpriseTask (使用代理)
https://api.capmonster.cloud/createTask
要求
{
"clientKey":"API_KEY",
"task": {
"type":"RecaptchaV2EnterpriseTaskProxyless",
"websiteURL":"https://mydomain.com/page-with-recaptcha-enterprise",
"websiteKey":"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
"enterprisePayload": {
"s": "SOME_ADDITIONAL_TOKEN"
}
}
}
回应
{
"errorId":0,
"taskId":407533072
}
https://api.capmonster.cloud/createTask
要求
{
"clientKey":"API_KEY",
"task": {
"type":"RecaptchaV2EnterpriseTask",
"websiteURL":"https://mydomain.com/page-with-recaptcha-enterprise",
"websiteKey":"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
"enterprisePayload": {
"s": "SOME_ADDITIONAL_TOKEN"
},
"proxyType":"http",
"proxyAddress":"8.8.8.8",
"proxyPort":8080,
"proxyLogin":"proxyLoginHere",
"proxyPassword":"proxyPasswordHere",
"userAgent":"userAgentPlaceholder"
}
}
回应
{
"errorId":0,
"taskId":407533072
}
获取任务结果方法
使用getTaskResult方法请求 ReCaptcha2 的答案。根据服务负载情况,您将在 10到80 秒内收到响应。
https://api.capmonster.cloud/getTaskResult
要求
{
"clientKey":"API_KEY",
"taskId": 407533072
}
回应
{
"errorId":0,
"status":"ready",
"solution": {
"gRecaptchaResponse":"3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3"
}
}
属性 | 类型 | 描述 |
---|---|---|
gRecaptchaResponse | String | 应插入到 Recaptcha2 提交表单中的哈希值 <textarea id="g-recaptcha-response" ..></textarea> 。长度为 500 到 2190 字节。 |
使用 SDK 库
- JavaScript
- Python
- C#
// https://github.com/ZennoLab/capmonstercloud-client-js
import { CapMonsterCloudClientFactory, ClientOptions, RecaptchaV2EnterpriseProxylessRequest, /*RecaptchaV2EnterpriseRequest*/ } from '@zennolab_com/capmonstercloud-client';
document.addEventListener('DOMContentLoaded', async () => {
const cmcClient = CapMonsterCloudClientFactory.Create(new ClientOptions({ clientKey: '<your capmonster.cloud API key>' }));
console.log(await cmcClient.getBalance());
const recaptchaV2EnterpriseRequest = new RecaptchaV2EnterpriseProxylessRequest({
websiteURL: 'https://mydomain.com/page-with-recaptcha-enterprise',
websiteKey: '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
enterprisePayload: {
s: 'SOME_ADDITIONAL_TOKEN',
},
});
// const recaptchaV2EnterpriseRequest = new RecaptchaV2EnterpriseRequest({
// websiteURL: 'https://mydomain.com/page-with-recaptcha-enterprise',
// websiteKey: '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
// enterprisePayload: {
// s: 'SOME_ADDITIONAL_TOKEN',
// },
// proxyType: 'http',
// proxyAddress: '8.8.8.8',
// proxyPort: 8080,
// proxyLogin: 'proxyLoginHere',
// proxyPassword: 'proxyPasswordHere',
// userAgent: 'userAgentPlaceholder',
// });
console.log(await cmcClient.Solve(recaptchaV2EnterpriseRequest));
});
# https://github.com/ZennoLab/capmonstercloud-client-python
# RecaptchaV2EnterpriseProxyless
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import RecaptchaV2EnterpriseProxylessRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonster Cloud API key
cap_monster_client = CapMonsterClient(options=client_options)
recaptcha2request = RecaptchaV2EnterpriseProxylessRequest(
websiteUrl="https://example.com", # Website with the captcha
websiteKey="6Lf26sUnAAAAAIKLuWNYgRsFUfmI-3Lex3xT5N-s", # Replace with your websiteKey
enterprisePayload={
"s": "SOME_ADDITIONAL_TOKEN"
}
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(recaptcha2request)
responses = asyncio.run(solve_captcha())
print(responses)
# ReCaptchaV2Enterprise:
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import RecaptchaV2EnterpriseRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonster Cloud API key
cap_monster_client = CapMonsterClient(options=client_options)
recaptcha2request = RecaptchaV2EnterpriseRequest(
websiteUrl="https://example.com", # Website with the captcha
websiteKey="6Lf26sUnAAAAAIKLuWNYgRsFUfmI-3Lex3xT5N-s", # Replace with your websiteKey
enterprisePayload={
"s": "SOME_ADDITIONAL_TOKEN"
},
proxy_type="http", # Proxy type (http, https, socks5)
proxy_address="8.8.8.8",
proxy_port=8080,
proxy_login="proxyLoginHere",
proxy_password="proxyPasswordHere"
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(recaptcha2request)
responses = asyncio.run(solve_captcha())
print(responses)
// https://github.com/ZennoLab/capmonstercloud-client-dotnet
// RecaptchaV2EnterpriseProxyless
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task Main(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var recaptchaV2EnterpriseRequest = new RecaptchaV2EnterpriseProxylessRequest
{
WebsiteUrl = "https://example.com", // Website with the captcha
WebsiteKey = "6Lf26sUnAAAAAIKLuWNYgRsFUfmI-3Lex3xT5N-s", // Replace with your website key
EnterprisePayload = "{\"s\":\"SOME_ADDITIONAL_TOKEN\"}"
};
var recaptchaV2EnterpriseResult = await cmCloudClient.SolveAsync(recaptchaV2EnterpriseRequest);
Console.WriteLine("Captcha Solution: " + recaptchaV2EnterpriseResult.Solution.Value);
}
}
// ReCaptchaV2Enterprise:
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task Main(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var recaptchaV2EnterpriseRequest = new RecaptchaV2EnterpriseRequest
{
WebsiteUrl = "https://example.com", // Website with the captcha
WebsiteKey = "6Lf26sUnAAAAAIKLuWNYgRsFUfmI-3Lex3xT5N-s", // Replace with your website key
EnterprisePayload = "{\"s\":\"SOME_ADDITIONAL_TOKEN\"}",
ProxyType = ProxyType.Http,
ProxyAddress = "8.8.8.8",
ProxyPort = 8080,
ProxyLogin = "proxyLoginHere",
ProxyPassword = "proxyPasswordHere"
};
var recaptchaV2EnterpriseResult = await cmCloudClient.SolveAsync(recaptchaV2EnterpriseRequest);
Console.WriteLine("Captcha Solution: " + recaptchaV2EnterpriseResult.Solution.Value);
}
}