Solve HCaptcha automatically via a proxy - HCaptchaTask
Hcaptcha devs call their captcha "a drop-in replacement for Recaptcha". We tried to create the same thing in our API, so task properties are absolutely the same as in RecaptchaV2Task except for the "type" property.
Related tutorial: Start from scratch and submit the form with Recaptcha v2 using NodeJS.
Important notice about User-Agent value. Previously it was possible to specify your own User-Agent for the tasks, but this had changed. Instead we provide the worker's user-agent which you need to use to bypass paid version of Hcaptcha. This was changed because nowadays it is almost impossible to emulate an alien user-agent in another platform, for example Chrome user-agent in Firefox. Browsers have large number of secondary artefacts besides navigator.userAgent, which belong specifically to one or another platform.

Captcha example
Task object
Property | Type | Required | Purpose | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type | String | Yes | HCaptchaTask | ||||||||||||||||||||||||
websiteURL | String | Yes | Address of a target web page. Can be located anywhere on the web site, even in a member area. Our workers don't navigate there but simulate the visit instead. | ||||||||||||||||||||||||
websiteKey | String | Yes | hCaptcha sitekey | ||||||||||||||||||||||||
proxyType | String | Yes | Type of proxy http - usual http/https proxy socks4 - socks4 proxy socks5 - socks5 proxy | ||||||||||||||||||||||||
proxyAddress | String | Yes | Proxy IP address ipv4/ipv6. No host names or IP addresses from local networks. | ||||||||||||||||||||||||
proxyPort | Integer | Yes | Proxy port | ||||||||||||||||||||||||
proxyLogin | String | No | Login for proxy which requires authorization (basic) | ||||||||||||||||||||||||
proxyPassword | String | No | Proxy password | ||||||||||||||||||||||||
Deprecated. Instead, use User-Agent from our workers which is returned by "getTaskResult" method. | |||||||||||||||||||||||||||
isInvisible | Boolean | No | Specify whether or not Hcaptcha is invisible. This will render an appropriate widget for our workers. | ||||||||||||||||||||||||
enterprisePayload | Object | No | Additional parameters which we'll use to rfeature3,ender Hcaptcha widget for Enterprise version.
|
Request example
CURL
curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST -d '{
"clientKey":"YOUR_API_KEY_HERE",
"task":
{
"type":"HCaptchaTask",
"websiteURL":"https://hcaptcha.com/",
"websiteKey":"00000000-0000-0000-0000-000000000000",
"proxyType":"http",
"proxyAddress":"8.8.8.8",
"proxyPort":8080,
"proxyLogin":"proxyLoginHere",
"proxyPassword":"proxyPasswordHere",
"isInvisible": false,
},
"softId": 0
}' https://api.anti-captcha.com/createTask
# Enterprise version:
curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST -d '{
"clientKey":"YOUR_API_KEY_HERE",
"task":
{
"type":"HCaptchaTask",
"websiteURL":"https://hcaptcha.com/",
"websiteKey":"00000000-0000-0000-0000-000000000000",
"proxyType":"http",
"proxyAddress":"8.8.8.8",
"proxyPort":8080,
"proxyLogin":"proxyLoginHere",
"proxyPassword":"proxyPasswordHere",
"isInvisible": false,
"enterprisePayload": {
"rqdata": "rqdata value from target website",
"sentry": true
}
},
"softId": 0
}' https://api.anti-captcha.com/createTask
PHP
<?php
//git clone git@github.com:AdminAnticaptcha/anticaptcha-php.git
include("anticaptcha.php");
include("hcaptcha.php");
$api = new HCaptcha();
$api->setVerboseMode(true);
//your anti-captcha.com account key
$api->setKey("YOUR_API_KEY_HERE");
//target website address
$api->setWebsiteURL("http://makeawebsitehub.com/recaptcha/test.php");
//hcaptcha key from target website
$api->setWebsiteKey("6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ");
//proxy access parameters
// DO NOT USE PURCHASED/RENTED PROXIES ON PROXY SERVICES!!!
// THEY WILL NOT WORK!
// USE ONLY PROXIES YOU INSTALL YOURSELF ON YOUR OWN SERVER OR FAST VPS
// USE PROPER PROXY SOFTWARE LIKE SQUID !
// INSTALLATION INSTRUCTIONS:
// https://anti-captcha.com/apidoc/articles/how-to-install-squid
$api->setProxyType("http");
$api->setProxyAddress("8.8.8.8");
$api->setProxyPort(1234);
//optional login and password
$api->setProxyLogin("login");
$api->setProxyPassword("password");
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
$api->setSoftId(0);
//optional invisible Hcaptcha flag
//$api->setIsInvisible();
//set Enterprise parameters this way:
//$api->setEnterprisePayload([
// "rqdata" => "somerqdata",
// "sentry" => true
//]);
//create task in API
if (!$api->createTask()) {
$api->debout("API v2 send failed - ".$api->getErrorMessage(), "red");
return false;
}
$taskId = $api->getTaskId();
//wait in a loop for max 300 seconds till task is solved
if (!$api->waitForResult(300)) {
echo "could not solve captcha\n";
echo $api->getErrorMessage()."\n";
} else {
$gResponse = $api->getTaskSolution();
echo "\n";
echo "your hcaptcha token: $gResponse\n\n";
}
Python
#pip3 install anticaptchaofficial
from anticaptchaofficial.hcaptchaproxyon import *
solver = hCaptchaProxyon()
solver.set_verbose(1)
solver.set_key("YOUR_API_KEY_HERE")
solver.set_website_url("https://hcaptcha.com/")
solver.set_website_key("00000000-0000-0000-0000-000000000000")
solver.set_proxy_address("PROXY_ADDRESS")
solver.set_proxy_port(1234)
solver.set_proxy_login("proxylogin")
solver.set_proxy_password("proxypassword")
solver.set_user_agent("Mozilla/5.0")
solver.set_cookies("test=true")
# tell API that Hcaptcha is invisible
#solver.set_is_invisible(1)
# set here parameters like rqdata, sentry, apiEndpoint, endpoint, reportapi, assethost, imghost
#solver.set_enterprise_payload({
# "rqdata": "rq data value from target website",
# "sentry": True
#})
# Specify softId to earn 10% commission with your app.
# Get your softId here: https://anti-captcha.com/clients/tools/devcenter
solver.set_soft_id(0)
g_response = solver.solve_and_return_solution()
if g_response != 0:
print "g-response: "+g_response
else:
print "task finished with error "+solver.error_code
NodeJS
//npm install @antiadmin/anticaptchaofficial
//https://github.com/AdminAnticaptcha/anticaptcha-npm
const ac = require("@antiadmin/anticaptchaofficial");
//set Hcaptcha Enterprise payload if any
const enterprisePayload = {
"rqdata": "rqdata from target website",
"sentry": true
//etc
}
//if it is non-Enteprise, set to null
//const enterprisePayload = null;
//set to true if you want us to render it in invisible mode
const isInvisible = false;
ac.setAPIKey('YOUR_API_KEY_HERE');
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
ac.setSoftId(0);
ac.solveHCaptchaProxyOn('http://DOMAIN.COM',
'WEBSITE_KEY',
'http', //http, socks4, socks5
'PROXY_ADDRESS',
'PROXY_PORT',
'PROXY_LOGIN',
'PROXY_PASSWORD',
'',
'some=cookies',
enterprisePayload,
isInvisible)
.then(gresponse => {
console.log('g-response: '+gresponse);
})
.catch(error => console.log('test received error '+error));
C#
//git clone git@github.com:AdminAnticaptcha/anticaptcha-csharp
using System;
using Anticaptcha_example.Api;
using Anticaptcha_example.Helper;
using Newtonsoft.Json.Linq;
namespace Anticaptcha_example
{
internal class Program
{
private static void Main() {
DebugHelper.VerboseMode = true;
var api = new HCaptcha
{
ClientKey = "YOUR_API_KEY_HERE",
WebsiteUrl = new Uri("http://makeawebsitehub.com/recaptcha/test.php"),
WebsiteKey = "6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ",
ProxyAddress = "xxx.xx.xx.xx",
ProxyPort = 1234,
ProxyLogin = "login",
ProxyPassword = "password",
UserAgent = "Opera 6.0",
// Specify softId to earn 10% commission with your app.
// Get your softId here:
// https://anti-captcha.com/clients/tools/devcenter
SoftId = 0
};
// use to set invisible mode
//api.IsInvisible = true
// use to set Hcaptcha Enterprise parameters like rqdata, sentry, apiEndpoint, endpoint, reportapi, assethost, imghost
//api.EnterprisePayload.Add("rqdata", "rqdata value from target website");
//api.EnterprisePayload.Add("sentry", "true");
if (!api.CreateTask())
DebugHelper.Out("API v2 send failed. " + api.ErrorMessage, DebugHelper.Type.Error);
else if (!api.WaitForResult())
DebugHelper.Out("Could not solve the captcha.", DebugHelper.Type.Error);
else
DebugHelper.Out("Result: " + api.GetTaskSolution().GRecaptchaResponse, DebugHelper.Type.Success);
}
}
}
Java
//git clone git@github.com:AdminAnticaptcha/anticaptcha-java.git
package com.anti_captcha;
import com.anti_captcha.Api.HCaptcha;
import com.anti_captcha.Helper.DebugHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;
public class Main {
public static void main(String[] args) throws InterruptedException, MalformedURLException, JSONException {
DebugHelper.setVerboseMode(true);
HCaptcha api = new HCaptcha();
api.setClientKey("API_KEY_HERE");
api.setWebsiteUrl(new URL("http://makeawebsitehub.com/HCaptcha/test.php"));
api.setWebsiteKey("6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ");
// proxy access parameters
// DO NOT USE PURCHASED/RENTED PROXIES WITH PROXY SERVICES!!!
// THEY WILL NOT WORK!
// USE ONLY PROXIES YOU INSTALL YOURSELF ON YOUR OWN SERVER OR FAST VPS
// USE PROPER PROXY SOFTWARE LIKE SQUID !
// INSTALLATION INSTRUCTIONS:
// https://anti-captcha.com/apidoc/articles/how-to-install-squid
api.setProxyType(NoCaptcha.ProxyTypeOption.HTTP);
api.setProxyAddress("xx.xxx.xx.xx");
api.setProxyPort(8282);
api.setProxyLogin("login");
api.setProxyPassword("password");
// uncomment to tell API that HCaptcha is in invisible mode
// api.setIsInvisible(true);
// uncomment and use for HCaptcha Enterprise version if you need to set parameters like rqdata, sentry, apiEndpoint, endpoint, reportapi, assethost, imghost
// JSONObject enterprisePayload = new JSONObject();
// try {
// enterprisePayload.put("rqdata", "rqdata from the target website");
// enterprisePayload.put("sentry", Boolean.TRUE);
// enterprisePayload.put("apiEndpoint", "https://...");
// } catch (Exception e) {
// DebugHelper.out("JSON error: "+e.getMessage(), DebugHelper.Type.ERROR);
// return;
// }
// api.setEnterprisePayload(enterprisePayload);
//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
api.setSoftId(0);
if (!api.createTask()) {
DebugHelper.out(
"API v2 send failed. " + api.getErrorMessage(),
DebugHelper.Type.ERROR
);
} else if (!api.waitForResult()) {
DebugHelper.out("Could not solve the captcha.", DebugHelper.Type.ERROR);
} else {
DebugHelper.out("Result: " + api.getTaskSolution().getGRecaptchaResponse(), DebugHelper.Type.SUCCESS);
}
}
}
Response example
JSON with no errors
{
"errorId": 0,
"taskId": 7654321
}
JSON with an error
{
"errorId": 1,
"errorCode": "ERROR_KEY_DOES_NOT_EXIST",
"errorDescription": "Account authorization key not found in the system"
}
Retrieve the solution
Use method getTaskResult to request the solution. Give the worker about 5 seconds before making your first request. If the worker is still busy, retry in 3 seconds.
Task solution object
Property | Type | Purpose |
---|---|---|
gRecaptchaResponse | String | Token string required for interacting with the submit form on the target website. |
respKey | String | Output of "window.hcaptcha.getRespKey()" function when it is available. Some websites use it for additional verification. |
userAgent | String | User-Agent of worker's browser. Use it when you submit the response token. |
Response example
JSON with no errors
{
"errorId":0,
"status":"ready",
"solution":
{
"gRecaptchaResponse":"3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3......",
"respKey":"E0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoiQk5vb1JuZ0FPSHBCM2EyWURSSC......",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
},
"cost":"0.001500",
"ip":"46.98.54.221",
"createTime":1472205564,
"endTime":1472205570,
"solveCount":"0"
}