# Pastebin gr9cDT2N require 'mechanize' require 'logger' agent = Mechanize.new agent.log = Logger.new $stdout begin agent.get "http://ruby-lang.org/en/foobar" rescue Mechanize::ResponseCodeError => ex p ex.page.class p ex.page end