Last active
April 4, 2023 02:09
-
-
Save SaraswatiSaud/dca49ed902871f53bad9fbeb6eb5a942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'kimurai' | |
gem 'two_captcha' | |
end | |
require 'kimurai' | |
require 'two_captcha' | |
class RecaptchaV2 < Kimurai::Base | |
API_KEY = 'XXXXXXXXXXXXXXXXXXXX' | |
URL = 'https://2captcha.com/demo/recaptcha-v2' | |
@name = 'recaptcha_v2_spider' | |
@engine = :selenium_chrome | |
@start_urls = [URL] | |
@config = { | |
user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36' | |
} | |
def parse(_response, _url, data: {}) | |
recaptcha = browser.find(:xpath, '//div[@id="recaptcha"]') | |
google_key = recaptcha['data-sitekey'] | |
client = TwoCaptcha.new(API_KEY) | |
options = { | |
googlekey: google_key, | |
pageurl: URL | |
} | |
captcha = client.decode_recaptcha_v2(options) | |
browser.execute_script("document.getElementById('g-recaptcha-response').style.display = 'block';") | |
browser.fill_in 'g-recaptcha-response', with: captcha.text | |
browser.execute_script("document.getElementById('g-recaptcha-response').style.display = 'none';") | |
browser.find(:css, '.btn_blue').click | |
end | |
end | |
RecaptchaV2.crawl! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment