Last active
December 19, 2015 08:29
-
-
Save biske/5926191 to your computer and use it in GitHub Desktop.
Google robot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2 gems should be installed:
sudo gem install capybara
sudo gem install selenium-webdriver