Git Product home page Git Product logo

captchasharp's Introduction

CaptchaSharp

A .NET Standard 2.0 library that implements the APIs of the most used captcha solving services out there. The library is fully documented, asynchronous and very easy to use. All services derive from the same CaptchaService class so you can allow users to use their favourite service without the need of a separate library for each one of them!

Supported Captchas

This library supports the following captcha types

  • Text (with language options)
  • Image (with options like phrase, case sensitivity, calculations)
  • FunCaptcha
  • ReCaptcha V2 (incl. invisible, enterprise)
  • ReCaptcha V3 (incl. enterprise)
  • HCaptcha
  • KeyCaptcha
  • GeeTest
  • Capy

Although this sounds very exciting, sadly not all captcha types are supported by the services. You can find a table of the supported captcha types for each major service below.

Supported Captcha Types

Adding CaptchaSharp to your project

Simply install the nuget package via

Install-Package CaptchaSharp

If you need more solvers you can install additional solvers (mostly ones that implement the 2captcha API) like this

Install-Package CaptchaSharp.Services.More

Usage

First of all, initialize your solver of choice by providing your credentials, for example

CaptchaService service = new TwoCaptchaService("MY_API_KEY");

You can get your remaining balance like this

decimal balance = await service.GetBalanceAsync();

If the provided credentials are wrong, the method above will return a BadAuthenticationException that you can catch and process in order to let the user know he needs to check his credentials.

If the credentials are correct and the balance is greater than the minimum required for solving a captcha, we can proceed to solve a ReCaptchaV2 task (you will need to provide the required parameters found in the webpage source code).

StringResponse solution = await service.SolveRecaptchaV2Async("site key", "site url");

The method above can throw the following exceptions:

  • TaskCreationException when the task could not be created for example due to zero balance or incorrect parameters.
  • TaskSolutionException when the task could not be completed, for example when an image captcha cannot be decoded.
  • TimeoutException when the captcha solution took too long to complete.

You can configure a custom timeout like this

service.Timeout = TimeSpan.FromMinutes(3);

The returned StringResponse will contain two fields:

An Id which you can use for reporting a bad solution (if the service supports it) like this

await service.ReportSolution(solution.Id, CaptchaType.ReCaptchaV2);

if the report failed, the method above will throw a TaskReportException.

And finally your solution as plaintext

Console.WriteLine($"The solution is {solution.Response}");

In addition, mind that not every service supports every type of captcha! If a method or specific parameters are not supported, a NotSupportedException will be thrown.

Unit Tests

Unit tests for the major services are included in the CaptchaSharp.Tests project. In order to test, you need to:

  1. Run any test once and let it fail. It will create a file called config.json in your bin/Debug folder.
  2. Add your credentials to the config.json file. You can also add a proxy to test proxied endpoints.
  3. Run the tests (one at a time, to avoid overloading the service and overspending).
  4. If you need to test a captcha on a specific website, you can edit the ServiceTests class and change the parameters as you need.

SolverTester

In addition, the solution also includes a WPF based solver that can be used to quickly test most of the features of the library to see if the methods work properly.

What needs to be improved

  • Use C# anonymous types or JObject for the AntiCaptchaSolver instead of a million classes!
  • Implement better exception handling, for example when there is zero balance or when a solver method returns a bad authentication, they will currently fall in the generic TaskCreationException type.

captchasharp's People

Contributors

openbullet avatar

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.