DataDome
这种验证码基本上要求用户通过移动滑块来解决拼图以进行确认。
此任务将使用我们的代理服务器执行。请在您的项目中使用收到的 Cookie 自动通过验证码。
请求参数
type
<string>requiredCustomTask
class
<string>requiredDataDome
websiteURL
<string>required解决验证码的主页面地址。
metadata.htmlPageBase64
<string>required (if metadata.captchaUrl is not filled)包含验证码附加数据的对象:"htmlPageBase64": "..."
- 一个 base64 编码的 HTML 页面,在对目标站点的 GET 请求响应中带有 403 状态码和 Set-Cookie: datadome="..." 头。
metadata.captchaUrl
<string>required (if metadata.htmlPageBase64 is not filled)"captchaUrl"
- 验证码链接。通常看起来像这样:"https://geo.captcha-delivery.com/captcha/?initialCid=..."
。
metadata.datadomeCookie
<string>required您的 datadome Cookie。您可以在页面上使用 "document.cookie" 获取,或在 Set-Cookie 请求头中获取:"datadome=..."(参见示例请求 /createTask)
userAgent
<string>optionalUser-Agent。
只通过实际的 UA。现在是: Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5.1 Mobile/21F90 Safari/604.1
proxyType
<string>optionalhttp - 普通的 http/https 代理;
https - 仅在 "http" 不起作用时尝试(某些自定义代理服务器要求);
socks4 - socks4 代理;
socks5 - socks5 代理。
proxyAddress
<string>optional代理 IP 地址 IPv4/IPv6。不允许:
- 使用主机名;
- 使用透明代理(其中客户端 IP 可见);
- 使用来自本地网络的代理。
proxyPort
<integer>optional代理端口。
proxyLogin
<string>optional代理登录。
proxyPassword
<string>optional代理密码。
创建任务方法
https://api.capmonster.cloud/createTask
要求
{
"clientKey": "API_KEY",
"task": {
"type": "CustomTask",
"class": "DataDome",
"websiteURL": "https://example.com",
"userAgent": "MuserAgentPlaceholder",
"metadata": {
"htmlPageBase64": "PGh0bWw+PGhlYWQ+PHRpdGxlPmJs...PC9odG1sPg==",
"datadomeCookie": "datadome=VYUWrgJ9ap4zmXq8Mgbp...64emvUPeON45z"
}
}
}
回应
{
"errorId":0,
"taskId":407533072
}
获取任务结果方法
使用 getTaskResult 方法获取 DataDome 的解决方案。
https://api.capmonster.cloud/getTaskResult
要求
{
"clientKey":"API_KEY",
"taskId": 407533072
}
回应
{
"errorId":0,
"status":"ready",
"solution": {
"domains": {
"site.com": {
"cookies": {
"datadome": "t355hfeuUFbsWpoMzXyIWL_ewfwgre25345323rwgregeFEkG5iju9esKVfWMzuLAjcfCIJUIHU7332At1l~HY78g782hidwfeO4K2ZP_CFHYUFEgygfiYGfGYEUfgyefWrXG6_3sy; Max-Age=31536000; Domain=.site.com; Path=/; Secure; SameSite=Lax"
}
}
}
}
}
使用 SDK 库
- JavaScript
- Python
- C#
// https://github.com/ZennoLab/capmonstercloud-client-js
import { CapMonsterCloudClientFactory, ClientOptions, DataDomeRequest } 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 dataDomeRequest = new DataDomeRequest({
websiteURL: 'https://example.com',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5.1 Mobile/21F90 Safari/604.1',
metadata: {
captchaUrl: 'https://geo.captcha-delivery.com/captcha/?initialCid=12434324',
datadomeCookie: '',
},
});
console.log(await cmcClient.Solve(dataDomeRequest));
});
# https://github.com/ZennoLab/capmonstercloud-client-python
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import DataDomeCustomTaskProxylessRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonster Cloud API key
cap_monster_client = CapMonsterClient(options=client_options)
data_dome_request = DataDomeCustomTaskProxylessRequest(
websiteUrl="https://example.com", # URL with the captcha
userAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5.1 Mobile/21F90 Safari/604.1", # Use the current userAgent
metadata={
"htmlPageBase64": "PGh0bWw+PGhlYWQ+PHRpdGxlPn...+48L2h0bWw+", # Replace with your HTML base64 or use captchaUrl
"datadomeCookie": "datadome=oZJnhpo...1PuyGg" # Replace with your DataDome cookie
}
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(data_dome_request)
responses = asyncio.run(solve_captcha())
print(responses)
// https://github.com/ZennoLab/capmonstercloud-client-dotnet
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task MainDatadome(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var DataDomeRequest = new DataDomeCustomTaskRequest(datadomeCookie: "datadome=6BvxqELMoorFNoo7GT1...JyfP_mhz", captchaUrl: "https://example.com", htmlPageBase64: "PGh0bWw+PGhlYWQ+PHRpdGxlPmJs...N0E5QTA1")
{
WebsiteUrl = "https://example.com",
UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5.1 Mobile/21F90 Safari/604.1", // Use the current userAgent
};
var DataDomeResult = await cmCloudClient.SolveAsync(DataDomeRequest);
Console.WriteLine("Captcha Solution: " + JsonSerializer.Serialize(DataDomeResult.Solution));
}
}