This is the easiest way to quickly integrate 2Captcha into your code and automate solving of any type of captcha. Examples of API requests for different captcha types are available on the Ruby captcha solver page.
- Ruby 2Captcha API Client (captcha solver)
- Installation
- Configuration
- Solve captcha
- Captcha options
- Normal Captcha
- Text Captcha
- reCAPTCHA v2
- reCAPTCHA v3
- reCAPTCHA Enterprise
- FunCaptcha
- GeeTest
- GeeTest V4
- KeyCaptcha
- Capy
- Grid
- Canvas
- ClickCaptcha
- Rotate
- Amazon WAF
- Cloudflare Turnstile
- Lemin Cropped Captcha
- Audio Captcha
- Yandex
- CyberSiARA
- DataDome
- MTCaptcha
- Friendly captcha
- Cutcaptcha
- Tencent
- atbCAPTCHA
- Other methods
- Proxies
- Error handling
- Examples
- Get in touch
- Join the team πͺ
- License
Add this line to your application's Gemfile:
gem 'ruby-2captcha'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ruby-2captcha
To use the api2captcha gem, you'll need to import the module and create a Client instance. Here's an example:
require 'api_2captcha'
client = Api2Captcha.new("YOUR_API_KEY")
There are a few options that can be configured using the Client instance:
client.api_key = "YOUR_API_KEY"
Option | Default value | Description |
---|---|---|
soft_id | 4584 | your software ID obtained after publishing in 2captcha software catalog |
callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in pingback settings of your account |
default_timeout | 120 | Timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from res.php API endpoint |
polling_interval | 10 | Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended |
Important
Once callback
is defined for Client
instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL.
To get the answer manually use get_result method
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.
Option | Default Value | Description |
---|---|---|
numeric | 0 | Defines if captcha contains numeric or other symbols see more info in the API docs |
min_len | 0 | minimal answer length |
max_len | 0 | maximum answer length |
phrase | 0 | defines if the answer contains multiple words or not |
case_sensitive | 0 | defines if the answer is case sensitive |
calc | 0 | defines captcha requires calculation |
lang | - | defines the captcha language, see the list of supported languages |
hint_image | - | an image with hint shown to workers with the captcha, translated into instructionsimg API parameter |
hint_text | - | hint or task text shown to workers with the captcha |
Below you can find basic examples for every captcha type, check out the code below.
To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.
result = client.normal({ image: 'path/to/captcha.jpg'})
# OR
result = client.normal({
image: 'https://site-with-captcha.com/path/to/captcha.jpg'
})
This method can be used to bypass a captcha that requires to answer a question provided in clear text.
result = client.text({
textcaptcha:'If tomorrow is Saturday, what day is today?',
lang: "en"
})
Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection.
result = client.recaptcha_v2({
googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
pageurl: 'https://mysite.com/page/with/recaptcha_v2',
invisible: 1
})
This method provides reCAPTCHA V3 solver and returns a token.
result = client.recaptcha_v3({
googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
pageurl: 'https://mysite.com/page/with/recaptcha_v3',
version: 'v3',
score: 0.3,
action: 'verify'
})
reCAPTCHA Enterprise can be used as reCAPTCHA V2 and reCAPTCHA V3. Below is a usage example for both versions.
# reCAPTCHA V2
result = client.recaptcha_v2({
googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
pageurl: 'https://mysite.com/page/with/recaptcha_v2_enterprise',
enterprise: 1
})
# reCAPTCHA V3
result = client.recaptcha_v3({
googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
pageurl: 'https://mysite.com/page/with/recaptcha_v3_enterprise',
version: 'v3',
score: 0.3,
action: 'verify',
enterprise: 1,
})
FunCaptcha (Arkoselabs) solving method. Returns a token.
result = client.funcaptcha({
publickey: "69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC",
pageurl: "https://mysite.com/page/with/funcaptcha",
surl: "https://client-api.arkoselabs.com"})
Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
result = client.geetest({
gt: 'f1ab2cdefa3456789012345b6c78d90e',
api_server: 'api-na.geetest.com',
challenge: '12345678abc90123d45678ef90123a456b',
pageurl: 'https://www.site.com/page/'
})
Use this method to solve GeeTest v4. Returns the response in JSON.
result = client.geetest_v4({
captcha_id: 'e392e1d7fd421dc63325744d5a2b9c73',
pageurl: 'https://www.site.com/page/'
})
Token-based method to solve KeyCaptcha.
result = client.keycaptcha({
s_s_c_user_id: 10,
s_s_c_session_id: '493e52c37c10c2bcdf4a00cbc9ccd1e8',
s_s_c_web_server_sign: '9006dc725760858e4c0715b835472f22-pz-',
s_s_c_web_server_sign2: '2ca3abe86d90c6142d5571db98af6714',
pageurl: 'https://www.keycaptcha.ru/demo-magnetic/'
})
Token-based method to bypass Capy puzzle captcha.
result = client.capy({
sitekey: 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
pageurl: 'http://mysite.com/',
api_server: 'https://jp.api.capy.me/'
})
Grid method is originally called Old reCAPTCHA V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.
result = client.grid({
image: 'path/to/captcha.jpg',
recaptcharows: 3,
recaptchacols: 3,
previous_id: 0,
lang: 'en',
imginstructions: 'path/to/hint.jpg',
textinstructions: 'Select all images with an Orange'
})
Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.
result = client.canvas({
image: 'path/to/captcha.jpg',
previous_id: 0,
lang: 'en',
hint_image: 'path/to/hint.jpg',
hint_text: 'Draw around apple'
})
ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.
result = client.coordinates({
image: 'path/to/captcha.jpg',
lang: 'en',
hint_image: 'path/to/hint.jpg',
hint_text: 'Connect the dots'
})
This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.
result = client.rotate({
image: 'path/to/captcha.jpg',
angle: 40,
lang: 'en',
hint_image: 'path/to/hint.jpg',
hint_text: 'Put the images in the correct way'
})
Use this method to solve Lemin challenge. Returns JSON with answer containing the following values: answer, challenge_id.
result = client.lemin({
captcha_id: 'CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
div_id: 'lemin-cropped-captcha',
pageurl: 'https://www.site.com/page/',
api_server: "https://api.leminnow.com/"
})
Use this method to solve Cloudflare Turnstile. Returns JSON with the token and User-Agent.
result = client.turnstile({
sitekey: "0x0AAAAAAADnPIDROzbs0Aaj",
data: "7fab0000b0e0ff00",
pagedata: "3gAFo2...0ME1UVT0=",
pageurl: "https://2captcha.com/",
action: "managed",
userAgent: "Mozilla/5.0 ... Chrome/116.0.0.0 Safari/537.36",
json: 1
})
Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat mitigation for Amazon AWS. Returns JSON with the token.
result = client.amazon_waf({
sitekey: '0x1AAAAAAAAkg0s2VIOD34y5',
iv: 'CgAHbCe2GgAAAAAj',
context: '9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc=',
pageurl: 'https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest',
challenge_script: "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
captcha_script: "https://41bcdd4fb3cb.610cd090.us-east-1.captcha.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/captcha.js"
})
Use the following method to bypass an audio captcha (mp3 formats only).
You must provide the language as lang = 'en'
. Supported languages are "en", "ru", "de", "el", "pt", "fr".
result = client.audio({
audio: 'path/to/audio.mp3',
lang: "en"
})
Use this method to solve Yandex and obtain a token to bypass the protection.
result = client.yandex({
sitekey: 'Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV',
url: "https://rutube.ru"
})
Use this method to solve CyberSiARA and obtain a token to bypass the protection.
result = client.cyber_siara({
pageurl: "https://test.com",
master_url_id: "12333-3123123"
})
Use this method to solve DataDome and obtain a token to bypass the protection.
Important
To solve the DataDome captcha, you must use a proxy. It is recommended to use residential proxies.
result = client.data_dome({
pageurl: "https://test.com",
captcha_url: "https://test.com/captcha/",
proxytype: "http",
proxy: "proxyuser:[email protected]:3128"
})
Use this method to solve MTCaptcha and obtain a token to bypass the protection.
result = client.mt_captcha({
pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
sitekey: "MTPublic-DemoKey9M"
})
Use this method to solve Friendly captcha and obtain a token to bypass the protection.
Important
To successfully use the received token, the captcha widget must not be loaded on the page. To do this, you need to abort request to /friendlycaptcha/...module.min.js
on the page. When the captcha widget is already loaded on the page, there is a high probability that the received token will not work.
result = client.friendly({
pageurl: "https://example.com",
sitekey: "2FZFEVS1FZCGQ9"
})
Use this method to solve Cutcaptcha and obtain a token to bypass the protection.
result = client.cutcaptcha({
misery_key: "a1488b66da00bf332a1488993a5443c79047e752",
api_key: "SAb83IIB",
pageurl: "https://example.cc/foo/bar.html"
})
Token-based method for automated solving of Tencent captcha.
result = client.tencent({
app_id: "197326679",
pageurl: "https://mysite.com/page/with/tencent"
})
Token-based method for automated solving of atbCAPTCHA.
result = client.atb_captcha({
app_id: "197326679",
api_server: "api.atb_captcha.com",
pageurl: "https://mysite.com/page/with/atb_captcha"
})
These methods can be used for manual captcha submission and answer polling.
# example for normal captcha
captcha_id = client.send('path/to/captcha.jpg')
# or for another captcha, for example for lemin
captcha_id = client.send({
method:"lemin",
captcha_id: "CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b",
api_server: "api.leminnow.com",
div_id: "lemin-cropped-captcha",
pageurl: "https://www.site.com/page/"
})
time.sleep(20)
# Get result
result = client.get_result(captcha_id)
Use this method to get your account's balance
balance = client.get_balance
Use this method to report good or bad captcha answer.
client.report(captcha_id, True) # captcha solved correctly
client.report(captcha_id, False) # captcha solved incorrectly
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, keycaptcha, capy puzzle, lemin, turnstile, amazon waf, Cutcaptcha, Friendly captcha, MTCaptcha, DataDome, CyberSiARA and etc. The proxy will be forwarded to the API to solve the captcha.
We have our own proxies that we can offer you. Buy residential proxies for avoid restrictions and blocks. Quick start.
Example solving reCAPTCHA V2 using proxy:
result = client.recaptcha_v2({
googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
pageurl: 'https://mysite.com/page/with/recaptcha_v2',
invisible: 1,
proxytype: "https",
proxy: "proxyuser:[email protected]:3128"
})
In case of an error, the captcha solver throws an exception. It's important to properly handle these cases. We recommend using begin rescue
to handle exceptions.
begin
result = client.text('If tomorrow is Saturday, what day is today?')
rescue Api2Captcha::ValidationException => e
# invalid parameters passed
puts(e)
rescue Api2Captcha::NetworkException => e
# network error occurred
puts(e)
rescue Api2Captcha::ApiException => e
# api respond with error
puts(e)
rescue Api2Captcha::TimeoutException => e
# captcha is not solved so far
puts(e)
end
Examples of solving all supported captcha types are located in the examples directory.
There are many ways to contribute, of which development is only one! Find your next job. Open positions: AI experts, scrapers, developers, technical support, and much more! π
The code in this repository is licensed under the MIT License. See the LICENSE file for more details.
The graphics and trademarks included in this repository are not covered by the MIT License. Please contact support for permissions regarding the use of these materials.