项目作者: ScreamZ

项目描述 :
A modern JS/TS wrapper around anti-captcha API (Captcha Breaker Software)
高级语言: TypeScript
项目地址: git://github.com/ScreamZ/anti-captcha.git
创建时间: 2017-10-18T17:38:49Z
项目社区:https://github.com/ScreamZ/anti-captcha

开源协议:

下载



AntiCaptcha




Modern NodeJS API wrapper for Anticaptcha service


Anticaptcha Logo



This library is a NodeJS wrapper that expose an modern API in order to exploit the https://anti-captcha.com/ service.

Please keep in mind that this is a work in progress and it only supports certain tasks types. Pull requests welcome!

Documentation

Install using either yarn add anticaptcha or npm i anticaptcha.

For the example, we will use the nice feature that are ES7 Async Function this will make the syntax more concise, but feel free to use good old Promises.

Caution : Keep in mind that real people are working behind the network to break the hash. This can lead to some delay depending on the service charge’s load, therefore you might require to set a greater timeout for your calls if you’re using this through an REST API.

  1. // main.js
  2. import {
  3. AntiCaptcha,
  4. AntiCaptchaError,
  5. ErrorCodes,
  6. INoCaptchaTaskProxyless,
  7. INoCaptchaTaskProxylessResult,
  8. QueueTypes,
  9. TaskTypes
  10. } from "anticaptcha";
  11. // Registering the API Client.
  12. const AntiCaptchaAPI = new AntiCaptcha("<your_client_ID>"); // You can pass true as second argument to enable debug logs.
  13. const mainProcess = async () => {
  14. try {
  15. // Checking the account balance before creating a task. This is a conveniance method.
  16. if (!(await AntiCaptchaAPI.isBalanceGreaterThan(10))) {
  17. // You can dispatch a warning using mailer or do whatever.
  18. console.warn("Take care, you're running low on money !");
  19. }
  20. // Get service stats
  21. const stats = await this.getQueueStats(QueueTypes.RECAPTCHA_PROXYLESS);
  22. // Creating nocaptcha proxyless task
  23. const taskId = await AntiCaptchaAPI.createTask<INoCaptchaTaskProxyless>({
  24. type: TaskTypes.NOCAPTCHA_PROXYLESS,
  25. websiteKey: "7Lfh5tkSBBBFGBGN56s8fAVds_Fl-HP0xQGNGFDK", // Some key from website
  26. websiteURL: "http://www.some-site.com" // Some URL from website
  27. });
  28. // Waiting for resolution and do something
  29. const response = await AntiCaptchaAPI.getTaskResult<
  30. INoCaptchaTaskProxylessResult
  31. >(taskId);
  32. console.log(`Response Code: ${response.solution.gRecaptchaResponse}`);
  33. } catch (e) {
  34. if (
  35. e instanceof AntiCaptchaError &&
  36. e.code === ErrorCodes.ERROR_IP_BLOCKED
  37. ) {
  38. // do something...
  39. }
  40. }
  41. };

When calling createTask or getTaskResult you’ll need to specify the task type. Check the TypeScript definition file that are given. This will give you nice view of the object properties. The following tasks are currently supported (other types are defined at: https://anticaptcha.atlassian.net/wiki/spaces/API/pages/5079084/Captcha+Task+Types):

  • IImageToTextTask (result type IImageToTextTaskResult)
  • INoCaptchaTaskProxyless (result type INoCaptchaTaskProxylessResult)
  • IRecaptchaV3TaskProxyless (result type IRecaptchaV3TaskProxylessResult)
  1. {
  2. status: "ready" | "processing";
  3. solution: T;
  4. cost: number;
  5. ip: string;
  6. createTime: number;
  7. endTime: number;
  8. /**
  9. * Number of workers who tried to complete your task
  10. *
  11. * @type {number}
  12. * @memberof IGetTaskResponse
  13. */
  14. solveCount: number;
  15. }