examples/link_checker.rb in metainspector-4.7.2 vs examples/link_checker.rb in metainspector-5.0.0.rc1
- old
+ new
@@ -1,12 +1,13 @@
# A basic spider that will follow internal links, checking broken links
#
# Usage example:
#
-# ruby link_checker.rb alazan.com
+# ruby link_checker.rb example.com
-require 'metainspector'
+require '../lib/metainspector'
+puts "Using MetaInspector #{MetaInspector::VERSION}"
class BrokenLinkChecker
def initialize(url)
@url = url
@@ -37,15 +38,15 @@
process_next_on_queue while @queue.any?
end
def process_next_on_queue
- page = MetaInspector.new(@queue.pop, :warn_level => :store)
+ page = MetaInspector.new(@queue.pop)
page.links.all.select {|l| l =~ /^http(s)?:\/\//i}.each do |link|
check_status(link, page.url)
- end if page.ok?
+ end
@visited.push(page.url)
page.links.internal.each do |link|
@queue.push(link) if should_be_enqueued?(link)
@@ -88,10 +89,10 @@
if page.response.status < 400
true
else
false
end
- rescue Exception => e
+ rescue
false
end
end
# Get the starting URL