Class WWW::Mechanize
In: lib/www/mechanize.rb
lib/www/mechanize/chain.rb
lib/www/mechanize/chain/auth_headers.rb
lib/www/mechanize/chain/body_decoding_handler.rb
lib/www/mechanize/chain/connection_resolver.rb
lib/www/mechanize/chain/custom_headers.rb
lib/www/mechanize/chain/header_resolver.rb
lib/www/mechanize/chain/parameter_resolver.rb
lib/www/mechanize/chain/pre_connect_hook.rb
lib/www/mechanize/chain/request_resolver.rb
lib/www/mechanize/chain/response_body_parser.rb
lib/www/mechanize/chain/response_header_handler.rb
lib/www/mechanize/chain/response_reader.rb
lib/www/mechanize/chain/ssl_resolver.rb
lib/www/mechanize/chain/uri_resolver.rb
lib/www/mechanize/content_type_error.rb
lib/www/mechanize/cookie.rb
lib/www/mechanize/cookie_jar.rb
lib/www/mechanize/file.rb
lib/www/mechanize/file_response.rb
lib/www/mechanize/file_saver.rb
lib/www/mechanize/form.rb
lib/www/mechanize/form/button.rb
lib/www/mechanize/form/check_box.rb
lib/www/mechanize/form/field.rb
lib/www/mechanize/form/file_upload.rb
lib/www/mechanize/form/image_button.rb
lib/www/mechanize/form/multi_select_list.rb
lib/www/mechanize/form/option.rb
lib/www/mechanize/form/radio_button.rb
lib/www/mechanize/form/select_list.rb
lib/www/mechanize/headers.rb
lib/www/mechanize/history.rb
lib/www/mechanize/monkey_patch.rb
lib/www/mechanize/page.rb
lib/www/mechanize/page/base.rb
lib/www/mechanize/page/frame.rb
lib/www/mechanize/page/link.rb
lib/www/mechanize/page/meta.rb
lib/www/mechanize/pluggable_parsers.rb
lib/www/mechanize/redirect_limit_reached_error.rb
lib/www/mechanize/redirect_not_get_or_head_error.rb
lib/www/mechanize/response_code_error.rb
lib/www/mechanize/unsupported_scheme_error.rb
lib/www/mechanize/util.rb
Parent: Object

Synopsis

The Mechanize library is used for automating interaction with a website. It can follow links, and submit forms. Form fields can be populated and submitted. A history of URL‘s is maintained and can be queried.

Example

 require 'rubygems'
 require 'mechanize'
 require 'logger'

 agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }
 agent.user_agent_alias = 'Mac Safari'
 page = agent.get("http://www.google.com/")
 search_form = page.form_with(:name => "f")
 search_form.field_with(:name => "q").value = "Hello"
 search_results = agent.submit(search_form)
 puts search_results.body

Methods

Classes and Modules

Class WWW::Mechanize::Chain
Class WWW::Mechanize::ContentTypeError
Class WWW::Mechanize::Cookie
Class WWW::Mechanize::CookieJar
Class WWW::Mechanize::File
Class WWW::Mechanize::FileResponse
Class WWW::Mechanize::FileSaver
Class WWW::Mechanize::Form
Class WWW::Mechanize::Headers
Class WWW::Mechanize::History
Class WWW::Mechanize::Page
Class WWW::Mechanize::PluggableParser
Class WWW::Mechanize::RedirectLimitReachedError
Class WWW::Mechanize::RedirectNotGetOrHeadError
Class WWW::Mechanize::ResponseCodeError
Class WWW::Mechanize::UnsupportedSchemeError
Class WWW::Mechanize::Util

Constants

VERSION = '0.9.2'   The version of Mechanize you are using.
AGENT_ALIASES = { 'Windows IE 6' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 'Windows IE 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', 'Windows Mozilla' => 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6', 'Mac Safari' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3', 'Mac FireFox' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3', 'Mac Mozilla' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4a) Gecko/20030401', 'Linux Mozilla' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624', 'Linux Konqueror' => 'Mozilla/5.0 (compatible; Konqueror/3; Linux)', 'iPhone' => 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3', 'Mechanize' => "WWW-Mechanize/#{VERSION} (http://rubyforge.org/projects/mechanize/)"   User Agent aliases

External Aliases

redirect_ok -> follow_redirect?

Attributes

ca_file  [RW] 
cert  [RW] 
conditional_requests  [RW] 
cookie_jar  [RW] 
follow_meta_refresh  [RW] 
history  [R] 
history_added  [RW] 
html_parser  [RW] 
keep_alive  [RW] 
keep_alive_time  [RW] 
key  [RW] 
log  [RW] 
open_timeout  [RW] 
pass  [RW] 
pluggable_parser  [R] 
read_timeout  [RW] 
redirect_ok  [RW] 
redirection_limit  [RW] 
scheme_handlers  [RW] 
user_agent  [RW] 
verify_callback  [RW] 
watch_for_set  [RW] 

Public Class methods

Public Instance methods

Sets the user and password to be used for authentication.

Equivalent to the browser back button. Returns the most recent page visited.

basic_auth(user, password)

Alias for auth

Clicks the WWW::Mechanize::Link object passed in and returns the page fetched.

Returns a list of cookies stored in the cookie jar.

Returns the current page loaded by Mechanize

DELETE to url with query_params, and setting options:

  delete('http://tenderlovemaking.com/', {'q' => 'foo'}, :headers => {})

Fetch a file and return the contents of the file.

HEAD to url with query_params, and setting options:

  head('http://tenderlovemaking.com/', {'q' => 'foo'}, :headers => {})
page()

Alias for current_page

Posts to the given URL wht the query parameters passed in. Query parameters can be passed as a hash, or as an array of arrays. Example:

 agent.post('http://example.com/', "foo" => "bar")

or

 agent.post('http://example.com/', [ ["foo", "bar"] ])

PUT to url with query_params, and setting options:

  put('http://tenderlovemaking.com/', {'q' => 'foo'}, :headers => {})

Sets the proxy address, port, user, and password addr should be a host, with no "http://"

Submit a form with an optional button. Without a button:

 page = agent.get('http://example.com')
 agent.submit(page.forms.first)

With a button

 agent.submit(page.forms.first, page.forms.first.buttons.first)

Runs given block, then resets the page history as it was before. self is given as a parameter to the block. Returns the value of the block.

Set the user agent for the Mechanize object. See AGENT_ALIASES

Returns whether or not a url has been visited

Returns a visited page for the url passed in, otherwise nil

[Validate]