Skip to content

Instantly share code, notes, and snippets.

@kawakami-o3
Created February 4, 2014 05:10
Show Gist options
  • Save kawakami-o3/8798455 to your computer and use it in GitHub Desktop.
Save kawakami-o3/8798455 to your computer and use it in GitHub Desktop.
Watir::Browswer.crawl
require 'watir-webdriver'
class Watir::Browser
def visited? url
if @history == nil
return false
end
return @history.index(url) != nil
end
def add_history url
if @history == nil
@history = []
end
@history << url
end
def crawl url
if visited? url
return
end
puts "goto: #{url}"
goto url
add_history url
urls = links.map{|i| i.href}.uniq
urls.each do |u|
crawl(u)
end
end
end
browser = Watir::Browser.new :ff
browser.crawl('http://www.google.com/')
browser.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment