Cookie使用通知

本网站会使用cookies,以便记住您的选择,并提供个性化服务。了解更多

如果网站速度慢,请使用网站链接 2captcha.cn
在Ruby中绕过captcha

在Ruby中绕过captcha

Ruby gem便于与captcha解析服务API集成,可绕过reCAPTCHA, hCaptcha, Arkose captcha, Geetest并解析任何其他captcha。这是将2Captcha 解析服务快速集成到代码中并自动求解任何类型captcha的最简单方法。

快速开始

安装

脚本包可通过安装程序安装或人工安装

Bundler

要安装gem,您可以使用bundler软件包管理器。从link下载,根据说明进行安装。

# Gemfile
gem 'ruby-2captcha'

我们邀请您探索我们的GitHub存储库,您可以在那里找到ruby API客户端,以便与我们的API轻松集成。

配置

配置已安装软件包的所有必要参数说明

Api2Captcha类实例可按照如下方法创建:

client = Api2Captcha.new('YOUR_API_KEY')

您还能为已创建的实例设置选项:

client = Api2Captcha.new("YOUR_API_KEY")
client.api_key = "YOUR_API_KEY"
Api2Captcha实例选项
选项默认值说明
soft_id-您将在2Captcha软件目录发布后获得软件ID
callback-验证码识别结果会发送至网络服务器URL,但应先在账户的pingback设置中注册URL
default_timeout120除reCAPTCHA外的验证码的轮询超时时间(秒),用于判定模块尝试从res.phpAPI端点获得答案的时间
recaptcha_timeout600reCAPTCHA的轮询超时时间(秒),用于判定模块尝试从res.phpAPI端点获得答案的时间
polling_interval10res.phpAPI端点发送请求的间隔时间(秒),不建议设置在5秒以内
重要提示:一旦回调函数确定用于Api2Captcha实例,那么所有方法都只返回验证码ID,无法通过轮询API获得结果。结果将发送至回调URL。请通过getResult方法进行人工破解。

破解验证码

您在提交图片验证码时可提出额外选项,以便2Captcha的员工能够正确破解。

验证码选项
选项默认值说明
numeric0判定验证码是否由数字或其他符号组成,详情请见API文档
min_len0最小答案长度
max_len0最大答案长度
phrase0判定答案是否由多个词语组成
case_sensitive0判定答案是否区分大小写
calc0确定验证码需要计算
lang-确定验证码语言,见可用语言列表
hint_image-所有验证码员工可见的提示图片
hint_text-员工可见的验证码提示或任务文字
simpleCaptcha

您可以利用以下方法绕过normal captcha(带有扭曲文字的图片)。这个方法也可用于识别图片上的任何文字。

result = client.normal({ image: 'path/to/captcha.jpg'})
# OR
result = client.normal({
  image: 'https://site-with-captcha.com/path/to/captcha.jpg'
})
textCaptcha

这种方法可用于绕过需要回答清晰文字问题的验证码。

result = client.text({
  textcaptcha:'If tomorrow is Saturday, what day is today?',
  lang: "en"
})
recaptchaV2

此方法可破解reCAPTCHA V2,并获得令牌实现绕过保护。

result = client.recaptcha_v2({
  googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
  pageurl: 'https://mysite.com/page/with/recaptcha_v2'
})
recaptchaV3

此方法利可破解reCAPTCHA V3,并返回令牌。

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)破解方法,并返回令牌。

result = client.funcaptcha({
  publickey: "69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC",
  pageurl: "https://mysite.com/page/with/funcaptcha",
  surl: "https://client-api.arkoselabs.com"
})
geeTest

此方法可破解GeeTest拼图验证码,并返回一组JSON格式的令牌。

result = client.geetest({
  gt: 'f1ab2cdefa3456789012345b6c78d90e',
  api_server: 'api-na.geetest.com',
  challenge: '12345678abc90123d45678ef90123a456b',
  pageurl: 'https://www.site.com/page/'
})
hCaptcha

此方法可破解hCaptcha,并返回可以绕过验证码的令牌。

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

通过令牌形式破解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

以令牌形式绕过Capy拼图验证码。

result = client.capy({
  sitekey: 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
  pageurl: 'http://mysite.com/',
  api_server: 'https://jp.api.capy.me/'
})
grid

Grid法最初名为Old reCAPTCHA V2法,先在图中画好网格,点击特定网格框,以绕过任何类型的验证码。这种方法会返回方框数。

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法需要围着图中物体画一条线。这种方法会返回一组点坐标,用于绘制多边形。

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会返回验证码图片的点坐标,若您需要点击图片的特定点,就可以使用这种方法。

result = client.coordinates({
  image: 'path/to/captcha.jpg',
  lang: 'en',
  hint_image: 'path/to/hint.jpg',
  hint_text: 'Connect the dots'
})
rotateCaptcha

这种方法可破解需要旋转物体的验证码,主要用于绕过FunCaptcha。它会返回旋转角度。

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

其他方法

主要脚本执行时可用的其他方法

send / get_result

上述方法可用于人工提交验证码和答案轮询。

# 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

以此方法获取账户余额。

balance = client.get_balance

report

以此方法报告验证码答案之优劣。

client.report(captcha_id, True) # captcha solved correctly
client.report(captcha_id, False) # captcha solved incorrectly

错误处理

网站在处理请求时返回的标准错误的可能变体

如果出现错误,captcha解析器引发异常。妥善处理这些情况很重要。我们建议使用begin/rescue来处理异常。

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

用于网站API集成的其他语言

  • PHP包,用于网站API集成

  • Python包,用于网站API集成

  • Java包,用于网站API集成

  • C#包,用于网站API集成

  • Golang包,用于网站API集成

  • JavaScript包,用于网站API集成

Chrome和Firefox浏览器均可使用验证码绕过扩展程序验证码绕过 扩展程序建议扩展CaptchaTheCat
我们支持VISA, Mastercard, Airtm, PayPal, Alipay, BTC, USDT支付系统。
«2Captcha»标志返回主页info@2captcha.com