GithubHelp home page GithubHelp logo

infosimples / node_two_captcha Goto Github PK

View Code? Open in Web Editor NEW
54.0 9.0 25.0 442 KB

Node package for 2Captcha (Captcha Solver as a Service)

License: MIT License

JavaScript 100.00%
2captcha npm node node-js two-captcha

node_two_captcha's Introduction

Node TwoCaptcha

npm version Maintainability

Node TwoCaptcha is a Javascript package for 2Captcha - 2Captcha.com.

Installation

Just run:

npm install @infosimples/node_two_captcha

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

Usage

1. Create a client

// 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

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

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 of the page with the reCAPTCHA challenge.
  • invisible: optional (Boolean) switch for invisible reCAPTCHA, default is false
  • enterprise: optional (Boolean) switch for reCAPTCHA Enterprise, default is false

reCAPTCHA v3

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 of the page with the reCAPTCHA challenge.
  • action: the action name used by the CAPTCHA.
  • enterprise: optional (Boolean) switch for reCAPTCHA Enterprise, default is false

hCaptcha

client.decodeHCaptcha({
  sitekey: 'the_key_extracted_from_the_page',
  pageurl: 'https://www.site.with.hcaptcha/example',
}).then(function(response) {
  console.log(response.text);
});

> P0_eyJ0eXAiIoJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiczHiam4vKzZnb...

decodeHCaptcha is an async function. The parameters for decodeHCaptcha function are:

  • sitekey: The site key for the hCaptcha.
  • pageurl: The URL of the page with the hCaptcha challenge.
  • invisible: optional (Boolean) switch for invisible hCaptcha, default is false.

3. Retrieve a previously solved captcha

// 61086191138 is the ID of a previously sent CAPTCHA
client.captcha('61086191138').then(function(response){
  console.log(response);
});

> Captcha {
   _id: '61086191138',
   _apiResponse: 'OK|infosimples',
   _text: 'infosimples' }

4. Report an incorrectly solved CATPCHA for a refund

client.report('61086191138').then(function(response) {
  console.log(response);
});

// Returns whether the report was received or not
> true

Or send a correct report by setting bad parameter to false. Default is true.

client.report('61086191138', false);

Warning: abusing on this method may get you banned.

5. Get usage statistics for a specific date

let date = new Date('2019-02-04');
client.stats(date).then(function(response) {
  console.log(response);
});

// Returns an XML string with your usage statistics
> <?xml version="1.0"?><response><stats dateint="1549227600" date="2019-02-04" hour="00"><volume>0</volume><money>0</money></stats><stats dateint="1549231200" date="2019-02-04" hour="01"><volume>0</volume><money>0</money></stats>...

6. Get your 2Captcha account balance

client.balance().then(function(response) {
  console.log(response);
});

// Returns a float with your account balance in USD
> 3.75371

node_two_captcha's People

Contributors

adrianodennanni avatar cezar-lima avatar dependabot[bot] avatar kratzky avatar kuzdogan avatar rafaelivan avatar smookeydev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node_two_captcha's Issues

Web Server is down

APIError: An Unexpected Error has occured. Please submit an issue on GitHub detailing this event.
at Solver.pollResponse (/home/gemweb/gemweb/src/gwrobots/node_modules/2captcha-ts/dist/structs/2captcha.js:117:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RobotCommands.solveCaptchaV3 (/home/gemweb/gemweb/src/gwrobots/src/Robots/Application/commands/RobotCommands.js:1460:9)
at async RobotIberdrolaInvoice.loginAttempt (/home/gemweb/gemweb/src/gwrobots/src/Robots/Infrastructure/Robots/Iberdrola/Iberdrola.js:68:35)
at async RobotIberdrolaInvoice.login (/home/gemweb/gemweb/src/gwrobots/src/Robots/Infrastructure/Robots/Iberdrola/Iberdrola.js:33:13)
at async Service.execute (/home/gemweb/gemweb/src/gwrobots/services/robot_invoice_services/robotInvoice.service.js:46:17)
at async Service.balancerSimple (/home/gemweb/gemweb/src/gwrobots/services/hub.service.js:193:17) {
err: '\n' +
'\n' +
'\n' +
'\n' +
' \n' +
'\n' +
'\n' +
'\n' +
'<title>2captcha.com | 521: Web server is down</title>\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'

\n' +
'
\n' +
' \n' +
'

\n' +
' Web server is down\n' +
' Error code 521\n' +
'

\n' +
'
\n' +
' Visit cloudflare.com for more information.\n' +
'
\n' +
'
2024-01-03 13:01:03 UTC
\n' +
' \n' +
'
\n' +
'
\n' +
'
\n' +
' \n' +
'
\n' +
'
\n' +
' \n' +
' \n' +
' \n' +
' \n' +
'
\n' +
' You\n' +
'

\n' +
' \n' +
' Browser\n' +
' \n' +
'

\n' +
' Working\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
' \n' +
' \n' +
' \n' +
'
\n' +
'
\n' +
' Madrid\n' +
'

\n' +
' \n' +
' Cloudflare\n' +
'
\n' +
'

\n' +
' Working\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
' \n' +
' \n' +
' \n' +
' \n' +
'
\n' +
' 2captcha.com\n' +
'

\n' +
' \n' +
' Host\n' +
' \n' +
'

\n' +
' Error\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'
\n' +
'

What happened?

\n' +
'

The web server is not returning a connection. As a result, the web page is not displaying.

\n' +
'
\n' +
'
\n' +
'

What can I do?

\n' +
'

If you are a visitor of this website:

\n' +
'

Please try again in a few minutes.

\n' +
'\n' +
'

If you are the owner of this website:

\n' +
'

Contact your hosting provider letting them know your web server is not responding. Additional troubleshooting information.

\n' +
'
\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'

\n' +
' Cloudflare Ray ID: 83fb6d9f0d3a1ba1\n' +
' \n' +
' \n' +
' Your IP:\n' +
' Click to reveal\n' +
' 46.27.218.82\n' +
' \n' +
'
\n' +
' Performance & security by Cloudflare\n' +
' \n' +
'

\n' +
' <script>(function(){function d(){var b=a.getElementById("cf-footer-item-ip"),c=a.getElementById("cf-footer-ip-reveal");b&&"classList"in b&&(b.classList.remove("hidden"),c.addEventListener("click",function(){c.classList.add("hidden");a.getElementById("cf-footer-ip").classList.remove("hidden")}))}var a=document;document.addEventListener&&a.addEventListener("DOMContentLoaded",d)})();</script>\n' +
'
\n' +
'\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'\n',
code: 0
}

[Issue] Incorrect captchas

I am trying to solve image-based captchas using this library, I also have funds in a 2captcha account.
Getting completely irrelevant & mismatch captchas suggestions.

letters aren't even close to the challenge, I am suspicious if 2captcha is scam or using bot to just reply with random characters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.