Skip to content

Instantly share code, notes, and snippets.

@biske
Last active December 19, 2015 08:29
Show Gist options
  • Save biske/5926191 to your computer and use it in GitHub Desktop.
Save biske/5926191 to your computer and use it in GitHub Desktop.
Google robot
require 'capybara/dsl'
require 'selenium-webdriver'
Capybara.run_server = false
Capybara.default_driver = :selenium
class GoogleRobot
include Capybara::DSL
def go
visit "http://www.google.com"
fill_in "q", with: "ruby"
find("#gbqfb").click
sleep 2 # it's bad practice but works
all(:xpath, '//*[@id="rso"]/li/div/h3/a').each do |result|
puts result.text
end
end
end
r = GoogleRobot.new
r.go
@biske
Copy link
Author

biske commented Jul 4, 2013

2 gems should be installed:
sudo gem install capybara
sudo gem install selenium-webdriver

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