Class: EasyCaptchaSolver
- Inherits:
-
Object
- Object
- EasyCaptchaSolver
- Defined in:
- lib/easy_captcha_solver.rb
Instance Attribute Summary collapse
-
#captcha ⇒ Object
readonly
Returns the value of attribute captcha.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ EasyCaptchaSolver
constructor
A new instance of EasyCaptchaSolver.
Constructor Details
#initialize(options = {}) ⇒ EasyCaptchaSolver
Returns a new instance of EasyCaptchaSolver.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/easy_captcha_solver.rb', line 7 def initialize ( = {} ) # Mechanize initializacion, pretends to be Mac Safari agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } @image = [:image_path] if [:image_path] # If URL, save a file instead of trying to solve the captcha from memory because of tesseract limitations with .png images if [:image_url] image = agent.get([:image_url]).save! "./tmp_image" # Guess image extension and rename tmp file @image = "./tmp_image.#{get_image_extension(image)}" File.rename( image, @image) end unless @image throw Exception.new "A local image path or a image URL must be provided. Example: easy_c = EasyCaptcha.new( image_url: 'http://www.example.com/captcha_img.jpg')" end solve_captcha ensure File.delete(@image) if [:image_url] end |
Instance Attribute Details
#captcha ⇒ Object (readonly)
Returns the value of attribute captcha.
5 6 7 |
# File 'lib/easy_captcha_solver.rb', line 5 def captcha @captcha end |