ReCaptchaV3: 解决 reCAPTCHA v3
提示
使用 createTask 方法创建任务,并使用 getTaskResult 方法获取结果。
我们支持的任务类型 types
:
ReCaptchaV3Task
此任务类型需要您自己的代理。ReCaptchaV3EnterpriseTask
此任务类型需要您自己的代理。ReCaptchaV3TaskProxyLess
使用服务器的内置代理。ReCaptchaV3EnterpriseTaskProxyLess
使用服务器的内置代理。
创建任务
使用 createTask 方法创建任务。
在创建任务之前,如果您需要在自动化工具(如 playwright 和 puppeteer)中使用令牌,您可能需要找到它们的回调函数。参考:
任务对象结构
警告
如果您不知道如何设置参数,请使用 CapSolver 扩展程序自动获取所需参数。
- 参考文章:如何检测任何验证码并提取其参数
如果您发现 v3 令牌无效,请使用 CapSolver 扩展程序获取 JSON 配置并发送给我们的客服进行配置。配置后,这将大大提高令牌分数。
属性 | 类型 | 必填 | 描述 |
---|---|---|---|
type | String | 必填 | ReCaptchaV3Task ReCaptchaV3TaskProxyLess ReCaptchaV3EnterpriseTask ReCaptchaV3EnterpriseTaskProxyLess |
websiteURL | String | 必填 | 带有 recaptcha 的网站地址。 |
websiteKey | String | 必填 | Recaptcha 网站密钥。 |
proxy | String | 可选 | 了解 使用代理。 |
pageAction | String | 可选 | 对于 ReCaptchaV3:您可以通过搜索 grecaptcha.execute 找到 action 参数的值。 |
enterprisePayload | Object | 可选 | 对于企业版,搜索 grecaptcha.enterprise.render 并传递 s 参数。 |
isSession | Bool | 可选 | 会话模式,启用后将返回 recaptcha-ca-t 值,用作 cookie。通常出现在 v3 中。注意:某些网站需要 recaptcha-ca-e 值,通常出现在 v2 中。如果存在此值,将自动返回,无需额外参数设置。 |
apiDomain | String | 可选 | 加载验证码的域名。通常不需要传递此参数。 • http://www.google.com/ • http://www.recaptcha.net/ |
请求示例
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ReCaptchaV2Task",
"websiteURL": "https://www.google.com/recaptcha/api2/demo",
"websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
"enterprisePayload": {
"s": "SOME_ADDITIONAL_TOKEN" // Optional
},
"isInvisible": false, // Optional
"pageAction": "submit", // Optional
"apiDomain": "", // Optional
"proxy": "http:ip:port:user:pass", // socks5:ip:port:user:pass, Optional
}
}
将任务提交给我们后,如果成功,您应该在响应中收到一个“taskId”。 如果您未收到任务 ID,请阅读 errorCode: 完整错误列表。
响应示例
{
"errorId": 0,
"errorCode": "",
"errorDescription": "",
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}
获取结果
拥有 taskId 后,您需要提交 taskId 以检索解决方案。响应结构在 getTaskResult 中有解释。
根据系统负载,您将在 1s
到 10s
的间隔内获得结果。
请求示例
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}
响应示例
{
"errorId": 0,
"errorCode": null,
"errorDescription": null,
"solution": {
"userAgent": "xxx", // User-Agent
"secChUa": "xxx", // Sec-Ch-Ua
"createTime": 1671615324290, // The creation time of the token
"gRecaptchaResponse": "3AHJ......", // token
"recaptcha-ca-t": "AbEM......", // Some v3 websites have session mode. After enabling isSession, this parameter will be returned and used as a cookie.
"recaptcha-ca-e": "Abp_......" // Some v2 websites have this parameter, which is used as a cookie. If there is such a value, it will be automatically returned.
},
"status": "ready"
}
使用 SDK 请求
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
"type": "ReCaptchaV3TaskProxyLess",
"websiteURL": "https://www.google.com",
"websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_kl-",
"pageAction": "login",
})
示例代码
# pip install requests
import requests
import time
# TODO: set your config
api_key = "YOUR_API_KEY" # your api key of capsolver
site_key = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_kl-" # site key of your target site
site_url = "https://www.google.com" # page url of your target site
def capsolver():
payload = {
"clientKey": api_key,
"task": {
"type": 'ReCaptchaV3TaskProxyLess',
"websiteKey": site_key,
"websiteURL": site_url,
"pageAction": "login",
}
}
res = requests.post("https://api.capsolver.com/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"Got taskId: {task_id} / Getting result...")
while True:
time.sleep(1) # delay
payload = {"clientKey": api_key, "taskId": task_id}
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
return resp.get("solution", {}).get('gRecaptchaResponse')
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
token = capsolver()
print(token)