Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
create Mechanize::Page object quickly from HTTP resource or local file
def mechanize_page( uri, base_uri = nil )
require 'kconv'
require 'rubygems'
require 'mechanize'
require 'hpricot'
WWW::Mechanize.html_parser = Hpricot
if ( URI( uri ).is_a?( URI::HTTP ) ) uri )
elsif ( File.exist?( uri ) )
base_uri = '' if base_uri.nil? URI( base_uri ),
{'content-type' => 'text/html'},
open( uri ).read.toutf8,
200, )
open( uri )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment