npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@infosimples/node_two_captcha

v1.2.0

Published

Node.js package for easy integration with 2Captcha API (Captcha Solver as a Service)

Downloads

17,914

Readme

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

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

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 where the hCaptcha is.
  • invisible: optional (Boolean) switch for invisible ReCaptcha, 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 incorrectly solved captcha for 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: do not abuse on this method, otherwise you may get 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