Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby code to crawl image from google.
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
option = { js_errors: false, timeout: 120 }
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, option)
end
session = Capybara::Session.new(:poltergeist)
url = "https://www.google.com/imghp?"
session.visit url
session.fill_in('q', with: 'Spritle Software')
session.click_button('Search')
image_url = session.first('img')['src']
puts image_url
session.driver.quit
@skydev2020

This comment has been minimized.

Copy link

@skydev2020 skydev2020 commented Nov 25, 2020

I get this error.
Capybara::Poltergeist::StatusFailError
/home/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/poltergeist-1.18.1/lib/capybara/poltergeist/browser.rb:396:in command' /home/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/poltergeist-1.18.1/lib/capybara/poltergeist/browser.rb:39:in visit'
/home/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/poltergeist-1.18.1/lib/capybara/poltergeist/driver.rb💯in visit' /home/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capybara-3.2.1/lib/capybara/session.rb:269:in visit'

How to solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment