Cookie usage notification

This site uses cookies. Cookies remember you, so we can provide you with personalized services. Read our privacy policy.

Bypass captcha in Ruby

Bypass captcha in Ruby

Ruby gem for easy integration with the API of captcha solving service to bypass reCAPTCHA, hCaptcha, Arkose captcha, Geetest and solve any other captchas. This is the easiest way to quickly integrate 2Captcha solving service into code and automate solving of any type of captcha.

Quick start

Installation

The script package can be installed using the package installer or manually

Bundler

To install a gem, you can use the bundler package manager. Download it from the link and install according to the instructions.

# Gemfile
gem 'ruby-2captcha'

We invite you to explore our GitHub repository where you can find ruby API client for easy integration with our API.

Configuration

Description of all the necessary parameters to configure the installed package

An instance of the Api2Captcha class can be created like this:

client = Api2Captcha.new('YOUR_API_KEY')

You also have the ability to customize some of the options for the created instance:

client = Api2Captcha.new("YOUR_API_KEY")
client.api_key = "YOUR_API_KEY"
Api2Captcha instance options
OptionDefault valueDescription
soft_id-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_timeout120Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from res.php API endpoint
recaptcha_timeout600Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from res.php API endpoint
polling_interval10Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended
IMPORTANT: once callback is defined for Api2Captcha 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 getResult method

Solve captcha

When you submit any image-based captcha use can provide additional options to help 2Captcha workers to solve it properly

Captcha options
OptionDefault valueDescription
numeric0Defines if captcha contains numeric or other symbols see more info in the API docs
min_len0minimal answer length
max_len0maximum answer length
phrase0defines if the answer contains multiple words or not
case_sensitive0defines if the answer is case sensitive
calc0defines 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
hint_text-hint or task text shown to workers with the captcha
simpleCaptcha

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'
})
textCaptcha

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"
})
recaptchaV2

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'
})
recaptchaV3

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'
})
funCaptcha

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"
})
geeTest

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/'
})
hCaptcha

Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.

result = client.hcaptcha({
  sitekey: '10000000-ffff-ffff-ffff-000000000001',
  pageurl: 'https://www.site.com/page/'
})
keyCaptcha

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/'
})
capy

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

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',
  rows: 3,
  cols: 3,
  previous_id: 0,
  lang: 'en',
  hint_image: 'path/to/hint.jpg',
  hint_text: 'Select all images with an Orange'
})
canvas

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

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'
})
rotateCaptcha

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'
})

Other methods

Additional valid methods used during the work of the main scripts

send / get_result

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)

get_balance

Use this method to get your account's balance.

balance = client.get_balance

report

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

Error handling

Possible variants of standard errors returned by the service when processing requests

If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use 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

Other languages for integration with the service API

We support VISA, Mastercard, Airtm, PayPal, Alipay, BTC, USDT payment systems
Logo of «2Captcha»To home pageinfo@2captcha.com