AntiCaptcha is a Ruby API for Anti-Captcha - Anti-Captcha.com
Add this line to your application's Gemfile:
gem 'anti_captcha'
And then execute:
$ bundle
Or install it yourself as:
$ gem install anti_captcha
client = AntiCaptcha.new('my_key')
There are two types of methods available: decode_*
and decode_*!
:
decode_*
does not raise exceptions.decode_*!
may raise aAntiCaptcha::Error
if something goes wrong.
If the solution is not available, an empty solution object will be returned.
solution = client.decode_image!(path: 'path/to/my/captcha/file')
solution.text # CAPTCHA solution
solution.url # Image URL
solution.task_result.task_id # The task ID
You can specify file
, body
or body64
when decoding an image.
client.decode_image!(file: File.open('path/to/my/captcha/file', 'rb'))
client.decode_image!(body: File.open('path/to/my/captcha/file', 'rb').read)
client.decode_image!(body64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
solution = client.decode_recaptcha_v2!(
website_key: 'xyz',
website_url: 'http://example.com/example=1',
# proxy_type: 'http', # OPTIONAL
# proxy_address: '127.0.0.1', # OPTIONAL
# proxy_port: '8080', # OPTIONAL
# proxy_login: 'proxyLoginHere', # OPTIONAL
# proxy_password: 'proxyPasswordHere', # OPTIONAL
# user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
)
solution.g_recaptcha_response
"03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
Parameters:
website_key
: the Google website key for the reCAPTCHA.website_url
: the URL of the page with the reCAPTCHA challenge.proxy_type
: optional parameter. Proxy connection protocol.proxy_address
: optional parameter. The proxy address.proxy_port
: optional parameter. The proxy port.proxy_login
: optional parameter. The proxy login.proxy_password
: optional parameter. The proxy password.user_agent
: optional parameter. The user agent.
solution = client.decode_recaptcha_v3!(
website_key: 'xyz',
website_url: 'http://example.com/example=1',
page_action: 'myverify',
min_score: 0.3, # OPTIONAL
# is_enterprise: false, # OPTIONAL
)
solution.g_recaptcha_response
"03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
Parameters:
website_key
: the Google website key for the reCAPTCHA.website_url
: the URL of the page with the reCAPTCHA challenge.action
: the action name used by the CAPTCHA.min_score
: optional parameter. The minimal score needed for the CAPTCHA resolution. Defaults to0.3
.is_enterprise
: optional parameter. Set totrue
if you are solving a reCAPTCHA v3 Enterprise. Defaults tofalse
.
About the
action
parameter: in order to find out what this is, you need to inspect the JavaScript code of the website looking for a call to thegrecaptcha.execute
function.// Example grecaptcha.execute('6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f', { action: "examples/v3scores" })
About the
min_score
parameter: it's strongly recommended to use a minimum score of0.3
as higher scores are rare.
solution = client.decode_h_captcha!(
website_key: 'xyz',
website_url: 'http://example.com/example=1',
# proxy_type: 'http', # OPTIONAL
# proxy_address: '127.0.0.1', # OPTIONAL
# proxy_port: '8080', # OPTIONAL
# proxy_login: 'proxyLoginHere', # OPTIONAL
# proxy_password: 'proxyPasswordHere', # OPTIONAL
# user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
)
solution.token
"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
# Or
solution.g_recaptcha_response # Deprecated
"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
Parameters:
website_key
: the site key for the hCatpcha.website_url
: the URL of the page with the hCaptcha challenge.proxy_type
: optional parameter. Proxy connection protocol.proxy_address
: optional parameter. The proxy address.proxy_port
: optional parameter. The proxy port.proxy_login
: optional parameter. The proxy login.proxy_password
: optional parameter. The proxy password.user_agent
: optional parameter. The user agent.
solution = client.decode_fun_captcha!(
website_public_key: 'xyz',
website_url: 'http://example.com/example=1',
# proxy_type: 'http', # OPTIONAL
# proxy_address: '127.0.0.1', # OPTIONAL
# proxy_port: '8080', # OPTIONAL
# proxy_login: 'proxyLoginHere', # OPTIONAL
# proxy_password: 'proxyPasswordHere', # OPTIONAL
# user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
)
solution.token
"380633616d817f2b8.2351188603|r=ap-southeast-2|met..."
Parameters:
website_key
: the site key for the hCatpcha.website_url
: the URL of the page with the hCaptcha challenge.proxy_type
: optional parameter. Proxy connection protocol.proxy_address
: optional parameter. The proxy address.proxy_port
: optional parameter. The proxy port.proxy_login
: optional parameter. The proxy login.proxy_password
: optional parameter. The proxy password.user_agent
: optional parameter. The user agent.
solution = client.decode_geetest!(
website_url: 'http://mywebsite.com/geetest/test.php',
gt: '874703612e5cac182812a00e273aad0d',
challenge: 'a559b82bca2c500101a1c8a4f4204742',
# proxy_type: 'http', # OPTIONAL
# proxy_address: '127.0.0.1', # OPTIONAL
# proxy_port: '8080', # OPTIONAL
# proxy_login: 'proxyLoginHere', # OPTIONAL
# proxy_password: 'proxyPasswordHere', # OPTIONAL
# user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
)
solution.v3['challenge']
"3c1c5153aa48011e92883aed820069f3hj"
solution.v3['validate']
"47ad5a0a6eb98a95b2bcd9e9eecc8272"
solution.v3['seccode']
"83fa4f2d23005fc91c3a015a1613f803|jordan"
# Or
solution.v4['captcha_id']
"fcd636b4514bf7ac4143922550b3008b"
solution.v4['lot_number']
"354ab6dd4e594fdc903074c4d8d37b24"
solution.v4['pass_token']
"b645946a654e60218c7922b74b3b5ee8e8717e8fd3cd51..."
solution.v4['gen_time']
"1649921519"
solution.v4['captcha_output']
"cFPIALDXSop8Ri2mPABbRWzNBs86N8D4vNUTuVa7wN7E..."
Parameters:
website_url
: URL of a target web page. It can be located anywhere on the web site, even in a member's area.gt
: the domain's public key.challenge
: changing token key. Make sure you grab a fresh one for each captcha.geetest_api_server_subdomain
: optional parameter. API subdomain. May be required for some implementations.geetest_get_lib
: optional parameter. Required for some implementations. Send the JSON encoded into a string. The value can be traced in the browser's developer tools. Put a breakpoint before calling the "initGeetest" function.version
: optional parameter. Version number. Default version is 3. Supported versions: 3 and 4.init_parameters
: optional parameter. Additional initialization parameters for version 4.proxy_type
: optional parameter. Proxy connection protocol.proxy_address
: optional parameter. The proxy address.proxy_port
: optional parameter. The proxy port.proxy_login
: optional parameter. The proxy login.proxy_password
: optional parameter. The proxy password.user_agent
: optional parameter. The user agent.
It is only possible to report incorrectly solved image CAPTCHAs.
client.report_incorrect_image_catpcha!(task_id)
client.get_balance!
Queue IDs:
1
Standart ImageToText, English language2
Standart ImageToText, Russian language5
Recaptcha NoCaptcha tasks6
Recaptcha Proxyless task7
Funcaptcha task10
Funcaptcha Proxyless task12
GeeTest with proxy13
GeeTest without proxy18
Recaptcha V3 s0.319
Recaptcha V3 s0.720
Recaptcha V3 s0.921
hCaptcha with proxy22
hCaptcha without proxy23
Recaptcha Enterprise V2 with proxy24
Recaptcha Enterprise V2 without proxy25
AntiGateTask
client.get_queue_stats!(queue_id)
AntiCaptcha doesn't require specific dependencies. That saves you memory and avoid conflicts with other gems.
Any format you use in the decode_image!
method (file
, path
, body
or body64
)
will always be converted to a body64
, which is a base64-encoded binary string.
So, if you already have this format on your end, there is no need for convertions
before calling the API.
Our recomendation is to never convert your image format, unless needed. Let the gem convert internally. It may save you resources (CPU, memory and IO).
AntiCaptcha gem uses Semantic Versioning.
MIT License. Copyright (C) 2011-2022 Infosimples. https://infosimples.com/