Loading repository data…
Loading repository data…
2captcha / repository
Java library for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, funcaptcha, geetest and solve any other captchas.
The easiest way to quickly integrate [2Captcha] into your code to automate solving of any types of captcha. Examples of API requests for different captcha types are available on the [Java captcha solver] page.
2captcha-java artifact is available in [Maven Central]
TwoCaptcha instance can be created like this:
TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');
Also there are few options that can be configured:
solver.setHost("2captcha.com");
solver.setSoftId(123);
solver.setCallback("https://your.site/result-receiver");
solver.setDefaultTimeout(120);
solver.setRecaptchaTimeout(600);
solver.setPollingInterval(10);
solver.setExtendedResponse(1);
| Option | Default value | Description |
|---|---|---|
| host | 2captcha.com | API server. You can set it to rucaptcha.com if your account is registered there |
| softId | 4581 | your software ID obtained after publishing in [2captcha software catalog] |
| callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account |
| defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from res.php API endpoint |
| recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from res.php API endpoint |
| pollingInterval | 10 | Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended |
| extendedResponse | 0 | Json or String format response from res.php API endpoint, extendedResponse = 1 returns JSON format response. Suitable for ClickCaptcha, Canvas |
[!IMPORTANT] Once callback URL is defined for
TwoCaptchainstance withsetCallback, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use getResult method
[!TIP] Use the
extendedResponse(1)setting to obtain an extended response for the captcha. When usingextendedResponse(1), the response will be presented as aJSONstring. Utilizing the extended responseextendedResponse(1)will be helpful when solving captchas such as ClickCaptcha.
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.
| Option | Default Value | Description |
|---|---|---|
| numeric | 0 | Defines if captcha contains numeric or other symbols [see more info in the API docs][post options] |
| minLength | 0 | minimal answer length |
| maxLength | 0 | maximum answer length |
| phrase | 0 | defines if the answer contains multiple words or not |
| caseSensitive | 0 | defines if the answer is case sensitive |
| calc | 0 | defines captcha requires calculation |
| lang | - | defines the captcha language, see the [list of supported languages] |
| hintImg | - | an image with hint shown to workers with the captcha |
| hintText | - | hint or task text shown to workers with the captcha |
Below you can find basic examples for every captcha type. Check out [examples directory] to find more examples with all available options.
Example below shows a basic solver call example with error handling.
Normal captcha = new Normal();
captcha.setFile("path/to/captcha.jpg");
captcha.setMinLen(4);
captcha.setMaxLen(20);
captcha.setCaseSensitive(true);
captcha.setLang("en");
try {
solver.solve(captcha);
System.out.println("Captcha solved: " + captcha.getCode());
} catch (Exception e) {
System.out.println("Error occurred: " + e.getMessage());
}
To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.
Normal captcha = new Normal();
captcha.setFile("path/to/captcha.jpg");
captcha.setNumeric(4);
captcha.setMinLen(4);
captcha.setMaxLen(20);
captcha.setPhrase(true);
captcha.setCaseSensitive(true);
captcha.setCalc(false);
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Type red symbols only");
This method can be used to bypass a captcha that requires to answer a question provided in clear text.
Text captcha = new Text();
captcha.setText("If tomorrow is Saturday, what day is today?");
captcha.setLang("en");
Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection.
ReCaptcha captcha = new ReCaptcha();
captcha.setSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.setUrl("https://mysite.com/page/with/recaptcha");
captcha.setInvisible(true);
captcha.setEnterprise(true);
captcha.setAction("verify");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");
captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36");
captcha.setCookies("KEY1:Value1;KEY2:Value2;");
This method provides reCAPTCHA V3 solver and returns a token.
ReCaptcha captcha = new ReCaptcha();
captcha.setSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.setUrl("https://mysite.com/page/with/recaptcha");
captcha.setVersion("v3");
captcha.setEnterprise(false);
captcha.setAction("verify");
captcha.setScore(0.3);
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");
FunCaptcha (Arkoselabs) solving method. Returns a token.
FunCaptcha captcha = new FunCaptcha();
captcha.setSiteKey("69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC");
captcha.setUrl("https://mysite.com/page/with/funcaptcha");
captcha.setSUrl("https://client-api.arkoselabs.com");
captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36");
captcha.setData("anyKey", "anyValue");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");
Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
GeeTest captcha = new GeeTest();
captcha.setGt("f2ae6cadcf7886856696502e1d55e00c");
captcha.setApiServer("api-na.geetest.com");
captcha.setChallenge("12345678abc90123d45678ef90123a456b");
captcha.setUrl("https://mysite.com/captcha.html");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");
Method to solve GeeTestV4 p