DEV Community

Cover image for How to bypass captcha in python using 2captcha
Raman Bansal
Raman Bansal

Posted on

How to bypass captcha in python using 2captcha

In this tutorial, we will learn how to bypass captcha using the 2captcha python package available on pypi.
While working on various projects, we have to use some third-party captcha solving services to do some automation. Let's understand them deeply.

How captcha solving services work?

These captcha solving services services have an API on which we send our captchas using POST / GET method. After that, employees resolve them and provide the result. In this article, we will access the 2captcha API with the help of Python ptogramming language.

Why 2captcha?

You may already solve many captchas while submitting a form or signing up for a website. The basic Captcha goal is to check whether the user is a human or a bot. Captcha stands for Completely Automated Public Turing test to tell Computers and Humans Apart. Captchas are used to stop spamming blogs, accessing bots, and making a website more secure.

Sometimes it is easy to solve the captcha, however, some of them are just a headache to the users, It might take minutes to think whether the letter is in Upper Case or Lower Case. Therefore, nowadays users prefer to use captcha-solving software.
What is 2Captcha?
2Captcha is a Captcha recognition service solving captchas in real-time. It also provides image recognition services powered by human intelligence. 2captcha can recognize different types of captcha and Its API is available for most programming languages. As the 2captcha uses the human-based method to solve captchas, It provides the opportunity to earn by solving the captchas.

Advantages of 2captcha

2captcha provides high level of accuracy
human-based method to recognise captchas
2captcha's average speed of recognising a captcha is less than 12 sec
API available for most popular and large no. programming languages like python, javascript etc.
2captcha can solve all kinds of captchas as it uses human-based method
2captcha service is very less-expensive

Pricing for customers

2captcha service is very affordable. Pricing of this service is fixed and very affordable. Let's see the pricing of their services.
2captcha charges only $0.71 for their customers.

Bypassing captcha using python

Firstly, we have to insert some modules/libraries for our tutorial.

Installation

We are using a module called 2captcha-python.

$ pip install 2captcha-python
Enter fullscreen mode Exit fullscreen mode

Basic configration

It is very easy to config 2captcha service.

from twocaptcha import TwoCaptcha
solver = TwoCaptcha('YOUR_API_KEY')
Enter fullscreen mode Exit fullscreen mode

Recognising local / downloaded jpg of captcha

result = solver.normal('path/to/captcha.jpg', param1=..., ...)

Enter fullscreen mode Exit fullscreen mode

Recognising captcha available on www

result = solver.normal('https://site-with-captcha.com/path/to/captcha.jpg', param1=..., ...)
Enter fullscreen mode Exit fullscreen mode

Recognising reCaptcha with 2captcha

You just have to specify the sitekey and url(on which you get recaptcha) to recognise recaptcha.

result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', url='https://mysite.com/page/with/recaptcha', param1=..., ...)
Enter fullscreen mode Exit fullscreen mode

Recognising GeeCaptcha

result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e', challenge='12345678abc90123d45678ef90123a456b', url='https://www.site.com/page/', param1=..., ...)
Enter fullscreen mode Exit fullscreen mode

Recognising hcaptcha

hCaptcha is basically the same as reCAPTCHA, but this not leads to benefit of a single company and also respects visitors privacy.

result = solver.hcaptcha(sitekey='10000000-ffff-ffff-ffff-000000000001', url='https://www.site.com/page/', param1=..., ...)
Enter fullscreen mode Exit fullscreen mode

Thanks

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.