Created
February 4, 2014 05:10
-
-
Save kawakami-o3/8798455 to your computer and use it in GitHub Desktop.
Watir::Browswer.crawl
This file contains 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 '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