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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.