@infosimples/node_two_captcha v1.1.0

CAPTCHAFORUM

Administrator
mqdefault[1].jpg


Node TwoCaptcha is a Javascript package for 2Captcha

Installation
Just run:
Code:
npm install @infosimples/node_two_captcha

JSDoc documentation can be found at https://infosimples.github.io/node_two_captcha/

Usage
1. Create a client
Code:
// Import module
const Client = require('@infosimples/node_two_captcha');
// Declare your client
client = new Client('your_2captcha_key', {
                    timeout: 60000,
                    polling: 5000,
                    throwErrors: false});

The first parameter of the TwoCaptchaClient constructor is your API key from 2Captcha. The other parameters are:
  • timeout: Time (milliseconds) to wait before giving up on waiting for a captcha solution.
  • polling: Time (milliseconds) between polls to 2captcha server. 2Captcha documentation suggests this time to be at least 5 seconds, or you might get blocked.
  • throwErrors: Whether the client should throw errors or just log the errors.
2. Solve a captcha
Image captcha
Code:
client.decode({
  url: 'http://bit.ly/1xXZcKo'
}).then(function(response) {
  console.log(response.text);
});
> infosimples

decode is an async function. Valid parameters for decode function are:
  • base64: An already base64-coded image.
  • buffer: A buffer object of a binary image.
  • path: The path for a system-stored image.
  • url: Url for a web-located image.
The returned value will be a Captcha object. Its properties are:
  • apiResponse: Complete API response body for captcha request.
  • id: Captcha ID, as provided from 2Captcha.
  • text: Text from captcha.
  • coordinates(): If the captcha sent was a image, this function returns the coordinates (X, Y) clicked.
  • indexes(): If the captcha sent was tile-like, this function returns the indexes of the clicks on an array.
ReCaptcha v2
Code:
client.decodeRecaptchaV2({
  googlekey: 'the_key_extracted_from_the_page',
  pageurl: 'https://www.google.com/recaptcha/api2/demo'
}).then(function(response) {
  console.log(response.text);
});
>jTfh3o9uqafa-u5RtYofHHo2uDk0T78f78HvttFGYft8pG3wuhd-UHAIy271bQXPeUNRm...
decodeRecaptchaV2 is an async function. The parameters for decodeRecaptchaV2 function are:
  • googlekey: The google key for the ReCaptcha.
  • pageurl: The URL where the ReCaptcha is.
  • invisible: optional (Boolean) switch for invisible ReCaptcha, default is false
  • enterprise: optional (Boolean) switch for ReCaptcha Enterprise, default is false
ReCaptcha v3
Code:
client.decodeRecaptchaV3({
  googlekey: 'the_key_extracted_from_the_page',
  pageurl: 'https://www.site.with.recaptcha.v3/example',
  action: 'test'
}).then(function(response) {
  console.log(response.text);
});
>jTfh3o9uqafa-u5RtYofHHo2uDk0T78f78HvttFGYft8pG3wuhd-UHAIy271bQXPeUNRm...
decodeRecaptchaV3 is an async function. The parameters for decodeRecaptchaV3 function are:

  • googlekey: The google key for the ReCaptcha.
  • pageurl: The URL where the ReCaptcha is.
  • action: the action value used by the captcha.
  • enterprise: optional (Boolean) switch for ReCaptcha Enterprise, default is false
Documentation https://infosimples.github.io/node_two_captcha/