#!/usr/bin/ruby # # $Id: example 4 2008-03-02 04:47:09Z warchild $ # require 'rubygems' require 'hawler' require 'hawleroptions' def blah (uri, referer, response) unless (response.nil? || response.body.nil?) puts "Got #{response.body.length} bytes visting #{uri} from #{referer}" @total += response.body.length end end # Handy helper class that will help you set # all of Hawler's options options = HawlerOptions.parse(ARGV) @total = 0 if (ARGV.empty?) puts "Need a URL to test" puts options.help exit(1) else # "Hawl" ARGV[0], feeding every visited URI to blah crawler = Hawler.new(ARGV[0], method(:blah)) # set all of Hawler's options options.each_pair do |o,v| crawler.send("#{o}=",v) end # godspeed! crawler.start puts "Got #{@total} bytes in total" end