13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/wtch.rb', line 13
def watch(url)
agent = Mechanize.new
stack = agent.get(url).links
while l = stack.pop
begin
next unless l.uri.host.nil? || l.uri.host == agent.history.first.uri.host
unless agent.visited? l.href
stack.push(*(agent.click(l).links))
Wtch.ui.info l.uri
end
rescue Errno::ECONNREFUSED, Mechanize::ResponseCodeError, ArgumentError, URI::InvalidComponentError, URI::InvalidURIError, NoMethodError, Mechanize::UnsupportedSchemeError => e
begin
Wtch.ui.error "#{e.message} (#{l.uri})"
rescue
Wtch.ui.error "#{e.message} (#{l.inspect})"
end
end
end
end
|