Watirにヒストリーを追加
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 |
かなり前に書いたものなので間違っているかもしれないです。
コメント
コメントを投稿