Skip to content

Instantly share code, notes, and snippets.

@jgrevich
Created May 1, 2013 20:17
Show Gist options
  • Save jgrevich/5498030 to your computer and use it in GitHub Desktop.
Save jgrevich/5498030 to your computer and use it in GitHub Desktop.
example of google search
module Scraper
class Google
include Capybara::DSL
Capybara.app_host = "http://www.google.com"
def search(query="I love Ruby!")
visit('/')
wait = 0 unless wait
sleep(wait)
wait += 5
fill_in("q", :with => query)
click_button "Google Search"
result = []
all("li.g h3").each do |h3|
a = h3.find("a")
result << "#{h3.text} => #{a[:href]}"
end
result
rescue Capybara::ElementNotFound
retry unless wait > 15
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment