/usr/local/share/man/man3
Edit: /usr/local/share/man/man3/WWW::Mechanize.3pm (68196B)
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
. if \nF \{
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "WWW::Mechanize 3"
.TH WWW::Mechanize 3 "2016-10-14" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
WWW::Mechanize \- Handy web browsing in a Perl object
.SH "VERSION"
.IX Header "VERSION"
version 1.83
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\f(CW\*(C`WWW::Mechanize\*(C'\fR, or Mech for short, is a Perl module for stateful
programmatic web browsing, used for automating interaction with
websites.
.PP
Features include:
.IP "\(bu" 4
All \s-1HTTP\s0 methods
.IP "\(bu" 4
High-level hyperlink and \s-1HTML\s0 form support, without having to parse \s-1HTML\s0 yourself
.IP "\(bu" 4
\&\s-1SSL\s0 support
.IP "\(bu" 4
Automatic cookies
.IP "\(bu" 4
Custom \s-1HTTP\s0 headers
.IP "\(bu" 4
Automatic handling of redirections
.IP "\(bu" 4
Proxies
.IP "\(bu" 4
\&\s-1HTTP\s0 authentication
.PP
Mech supports performing a sequence of page fetches including
following links and submitting forms. Each fetched page is parsed
and its links and forms are extracted. A link or a form can be
selected, form fields can be filled and the next page can be fetched.
Mech also stores a history of the URLs you've visited, which can
be queried and revisited.
.PP
.Vb 2
\& use WWW::Mechanize;
\& my $mech = WWW::Mechanize\->new();
\&
\& $mech\->get( $url );
\&
\& $mech\->follow_link( n => 3 );
\& $mech\->follow_link( text_regex => qr/download this/i );
\& $mech\->follow_link( url => \*(Aqhttp://host.com/index.html\*(Aq );
\&
\& $mech\->submit_form(
\& form_number => 3,
\& fields => {
\& username => \*(Aqmungo\*(Aq,
\& password => \*(Aqlost\-and\-alone\*(Aq,
\& }
\& );
\&
\& $mech\->submit_form(
\& form_name => \*(Aqsearch\*(Aq,
\& fields => { query => \*(Aqpot of gold\*(Aq, },
\& button => \*(AqSearch Now\*(Aq
\& );
.Ve
.PP
Mech is well suited for use in testing web applications. If you use
one of the Test::*, like Test::HTML::Lint modules, you can check the
fetched content and use that as input to a test call.
.PP
.Vb 2
\& use Test::More;
\& like( $mech\->content(), qr/$expected/, "Got expected content" );
.Ve
.PP
Each page fetch stores its \s-1URL\s0 in a history stack which you can
traverse.
.PP
.Vb 1
\& $mech\->back();
.Ve
.PP
If you want finer control over your page fetching, you can use
these methods. \f(CW\*(C`follow_link\*(C'\fR and \f(CW\*(C`submit_form\*(C'\fR are just high
level wrappers around them.
.PP
.Vb 7
\& $mech\->find_link( n => $number );
\& $mech\->form_number( $number );
\& $mech\->form_name( $name );
\& $mech\->field( $name, $value );
\& $mech\->set_fields( %field_values );
\& $mech\->set_visible( @criteria );
\& $mech\->click( $button );
.Ve
.PP
WWW::Mechanize is a proper subclass of LWP::UserAgent and
you can also use any of LWP::UserAgent's methods.
.PP
.Vb 1
\& $mech\->add_header($name => $value);
.Ve
.PP
Please note that Mech does \s-1NOT\s0 support JavaScript, you need additional software
for that. Please check \*(L"JavaScript\*(R" in WWW::Mechanize::FAQ for more.
.SH "IMPORTANT LINKS"
.IX Header "IMPORTANT LINKS"
.IP "\(bu" 4
.Sp
The queue for bugs & enhancements in WWW::Mechanize and
Test::WWW::Mechanize. Please note that the queue at
is no longer maintained.
.IP "\(bu" 4
.Sp
The \s-1CPAN\s0 documentation page for Mechanize.
.IP "\(bu" 4
.Sp
Frequently asked questions. Make sure you read here \s-1FIRST.\s0
.SH "CONSTRUCTOR AND STARTUP"
.IX Header "CONSTRUCTOR AND STARTUP"
.SS "\fInew()\fP"
.IX Subsection "new()"
Creates and returns a new WWW::Mechanize object, hereafter referred to as
the \*(L"agent\*(R".
.PP
.Vb 1
\& my $mech = WWW::Mechanize\->new()
.Ve
.PP
The constructor for WWW::Mechanize overrides two of the parms to the
LWP::UserAgent constructor:
.PP
.Vb 2
\& agent => \*(AqWWW\-Mechanize/#.##\*(Aq
\& cookie_jar => {} # an empty, memory\-only HTTP::Cookies object
.Ve
.PP
You can override these overrides by passing parms to the constructor,
as in:
.PP
.Vb 1
\& my $mech = WWW::Mechanize\->new( agent => \*(Aqwonderbot 1.01\*(Aq );
.Ve
.PP
If you want none of the overhead of a cookie jar, or don't want your
bot accepting cookies, you have to explicitly disallow it, like so:
.PP
.Vb 1
\& my $mech = WWW::Mechanize\->new( cookie_jar => undef );
.Ve
.PP
Here are the parms that WWW::Mechanize recognizes. These do not include
parms that LWP::UserAgent recognizes.
.IP "\(bu" 4
\&\f(CW\*(C`autocheck => [0|1]\*(C'\fR
.Sp
Checks each request made to see if it was successful. This saves
you the trouble of manually checking yourself. Any errors found
are errors, not warnings.
.Sp
The default value is \s-1ON,\s0 unless it's being subclassed, in which
case it is \s-1OFF. \s0 This means that standalone WWW::Mechanizeinstances
have autocheck turned on, which is protective for the vast majority
of Mech users who don't bother checking the return value of \fIget()\fR
and \fIpost()\fR and can't figure why their code fails. However, if
WWW::Mechanize is subclassed, such as for Test::WWW::Mechanize
or Test::WWW::Mechanize::Catalyst, this may not be an appropriate
default, so it's off.
.IP "\(bu" 4
\&\f(CW\*(C`noproxy => [0|1]\*(C'\fR
.Sp
Turn off the automatic call to the LWP::UserAgent \f(CW\*(C`env_proxy\*(C'\fR function.
.Sp
This needs to be explicitly turned off if you're using Crypt::SSLeay to
access a https site via a proxy server. Note: you still need to set your
\&\s-1HTTPS_PROXY\s0 environment variable as appropriate.
.IP "\(bu" 4
\&\f(CW\*(C`onwarn => \e&func\*(C'\fR
.Sp
Reference to a \f(CW\*(C`warn\*(C'\fR\-compatible function, such as \f(CW\*(C`Carp::carp\*(C'\fR,
that is called when a warning needs to be shown.
.Sp
If this is set to \f(CW\*(C`undef\*(C'\fR, no warnings will ever be shown. However,
it's probably better to use the \f(CW\*(C`quiet\*(C'\fR method to control that behavior.
.Sp
If this value is not passed, Mech uses \f(CW\*(C`Carp::carp\*(C'\fR if Carp is
installed, or \f(CW\*(C`CORE::warn\*(C'\fR if not.
.IP "\(bu" 4
\&\f(CW\*(C`onerror => \e&func\*(C'\fR
.Sp
Reference to a \f(CW\*(C`die\*(C'\fR\-compatible function, such as \f(CW\*(C`Carp::croak\*(C'\fR,
that is called when there's a fatal error.
.Sp
If this is set to \f(CW\*(C`undef\*(C'\fR, no errors will ever be shown.
.Sp
If this value is not passed, Mech uses \f(CW\*(C`Carp::croak\*(C'\fR if Carp is
installed, or \f(CW\*(C`CORE::die\*(C'\fR if not.
.IP "\(bu" 4
\&\f(CW\*(C`quiet => [0|1]\*(C'\fR
.Sp
Don't complain on warnings. Setting \f(CW\*(C`quiet => 1\*(C'\fR is the same as
calling \f(CW\*(C`$mech\->quiet(1)\*(C'\fR. Default is off.
.IP "\(bu" 4
\&\f(CW\*(C`stack_depth => $value\*(C'\fR
.Sp
Sets the depth of the page stack that keeps track of all the
downloaded pages. Default is effectively infinite stack size. If
the stack is eating up your memory, then set this to a smaller
number, say 5 or 10. Setting this to zero means Mech will keep no
history.
.PP
To support forms, WWW::Mechanize's constructor pushes \s-1POST\s0
on to the agent's \f(CW\*(C`requests_redirectable\*(C'\fR list (see also
LWP::UserAgent.)
.ie n .SS "$mech\->agent_alias( $alias )"
.el .SS "\f(CW$mech\fP\->agent_alias( \f(CW$alias\fP )"
.IX Subsection "$mech->agent_alias( $alias )"
Sets the user agent string to the expanded version from a table of actual user strings.
\&\fI\f(CI$alias\fI\fR can be one of the following:
.IP "\(bu" 4
Windows \s-1IE 6\s0
.IP "\(bu" 4
Windows Mozilla
.IP "\(bu" 4
Mac Safari
.IP "\(bu" 4
Mac Mozilla
.IP "\(bu" 4
Linux Mozilla
.IP "\(bu" 4
Linux Konqueror
.PP
then it will be replaced with a more interesting one. For instance,
.PP
.Vb 1
\& $mech\->agent_alias( \*(AqWindows IE 6\*(Aq );
.Ve
.PP
sets your User-Agent to
.PP
.Vb 1
\& Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
.Ve
.PP
The list of valid aliases can be returned from \f(CW\*(C`known_agent_aliases()\*(C'\fR. The current list is:
.IP "\(bu" 4
Windows \s-1IE 6\s0
.IP "\(bu" 4
Windows Mozilla
.IP "\(bu" 4
Mac Safari
.IP "\(bu" 4
Mac Mozilla
.IP "\(bu" 4
Linux Mozilla
.IP "\(bu" 4
Linux Konqueror
.SS "\fIknown_agent_aliases()\fP"
.IX Subsection "known_agent_aliases()"
Returns a list of all the agent aliases that Mech knows about.
.SH "PAGE-FETCHING METHODS"
.IX Header "PAGE-FETCHING METHODS"
.ie n .SS "$mech\->get( $uri )"
.el .SS "\f(CW$mech\fP\->get( \f(CW$uri\fP )"
.IX Subsection "$mech->get( $uri )"
Given a \s-1URL/URI,\s0 fetches it. Returns an HTTP::Response object.
\&\fI\f(CI$uri\fI\fR can be a well-formed \s-1URL\s0 string, a \s-1URI\s0 object, or a
WWW::Mechanize::Link object.
.PP
The results are stored internally in the agent object, but you don't
know that. Just use the accessors listed below. Poking at the
internals is deprecated and subject to change in the future.
.PP
\&\f(CW\*(C`get()\*(C'\fR is a well-behaved overloaded version of the method in
LWP::UserAgent. This lets you do things like
.PP
.Vb 1
\& $mech\->get( $uri, \*(Aq:content_file\*(Aq => $tempfile );
.Ve
.PP
and you can rest assured that the parms will get filtered down
appropriately.
.PP
\&\fB\s-1NOTE:\s0\fR Because \f(CW\*(C`:content_file\*(C'\fR causes the page contents to be
stored in a file instead of the response object, some Mech functions
that expect it to be there won't work as expected. Use with caution.
.ie n .SS "$mech\->put( $uri, content => $content )"
.el .SS "\f(CW$mech\fP\->put( \f(CW$uri\fP, content => \f(CW$content\fP )"
.IX Subsection "$mech->put( $uri, content => $content )"
PUTs \fI\f(CI$content\fI\fR to \f(CW$uri\fR. Returns an HTTP::Response object.
\&\fI\f(CI$uri\fI\fR can be a well-formed \s-1URI\s0 string, a \s-1URI\s0 object, or a
WWW::Mechanize::Link object.
.ie n .SS "$mech\->\fIreload()\fP"
.el .SS "\f(CW$mech\fP\->\fIreload()\fP"
.IX Subsection "$mech->reload()"
Acts like the reload button in a browser: repeats the current
request. The history (as per the \*(L"back\*(R" method) is not altered.
.PP
Returns the HTTP::Response object from the reload, or \f(CW\*(C`undef\*(C'\fR
if there's no current request.
.ie n .SS "$mech\->\fIback()\fP"
.el .SS "\f(CW$mech\fP\->\fIback()\fP"
.IX Subsection "$mech->back()"
The equivalent of hitting the \*(L"back\*(R" button in a browser. Returns to
the previous page. Won't go back past the first page. (Really, what
would it do if it could?)
.PP
Returns true if it could go back, or false if not.
.ie n .SS "$mech\->\fIhistory_count()\fP"
.el .SS "\f(CW$mech\fP\->\fIhistory_count()\fP"
.IX Subsection "$mech->history_count()"
This returns the number of items in the browser history. This number \fIdoes\fR
include the most recently made request.
.ie n .SS "$mech\->history($n)"
.el .SS "\f(CW$mech\fP\->history($n)"
.IX Subsection "$mech->history($n)"
This returns the \fIn\fRth item in history. The 0th item is the most recent
request and response, which would be acted on by methods like \f(CW\*(C`find_link()\*(C'\fR.
The 1th item is the state you'd return to if you called \f(CW\*(C`back()\*(C'\fR.
.PP
The maximum useful value for \f(CW$n\fR is \f(CW\*(C`$mech\->history_count \- 1\*(C'\fR.
Requests beyond that bound will return \f(CW\*(C`undef\*(C'\fR.
.PP
History items are returned as hash references, in the form:
.PP
.Vb 1
\& { req => $http_request, res => $http_response }
.Ve
.SH "STATUS METHODS"
.IX Header "STATUS METHODS"
.ie n .SS "$mech\->\fIsuccess()\fP"
.el .SS "\f(CW$mech\fP\->\fIsuccess()\fP"
.IX Subsection "$mech->success()"
Returns a boolean telling whether the last request was successful.
If there hasn't been an operation yet, returns false.
.PP
This is a convenience function that wraps \f(CW\*(C`$mech\->res\->is_success\*(C'\fR.
.ie n .SS "$mech\->\fIuri()\fP"
.el .SS "\f(CW$mech\fP\->\fIuri()\fP"
.IX Subsection "$mech->uri()"
Returns the current \s-1URI\s0 as a \s-1URI\s0 object. This object stringifies
to the \s-1URI\s0 itself.
.ie n .SS "$mech\->\fIresponse()\fP / $mech\->\fIres()\fP"
.el .SS "\f(CW$mech\fP\->\fIresponse()\fP / \f(CW$mech\fP\->\fIres()\fP"
.IX Subsection "$mech->response() / $mech->res()"
Return the current response as an HTTP::Response object.
.PP
Synonym for \f(CW\*(C`$mech\->response()\*(C'\fR
.ie n .SS "$mech\->\fIstatus()\fP"
.el .SS "\f(CW$mech\fP\->\fIstatus()\fP"
.IX Subsection "$mech->status()"
Returns the \s-1HTTP\s0 status code of the response. This is a 3\-digit
number like 200 for \s-1OK, 404\s0 for not found, and so on.
.ie n .SS "$mech\->\fIct()\fP / $mech\->\fIcontent_type()\fP"
.el .SS "\f(CW$mech\fP\->\fIct()\fP / \f(CW$mech\fP\->\fIcontent_type()\fP"
.IX Subsection "$mech->ct() / $mech->content_type()"
Returns the content type of the response.
.ie n .SS "$mech\->\fIbase()\fP"
.el .SS "\f(CW$mech\fP\->\fIbase()\fP"
.IX Subsection "$mech->base()"
Returns the base \s-1URI\s0 for the current response
.ie n .SS "$mech\->\fIforms()\fP"
.el .SS "\f(CW$mech\fP\->\fIforms()\fP"
.IX Subsection "$mech->forms()"
When called in a list context, returns a list of the forms found in
the last fetched page. In a scalar context, returns a reference to
an array with those forms. The forms returned are all HTML::Form
objects.
.ie n .SS "$mech\->\fIcurrent_form()\fP"
.el .SS "\f(CW$mech\fP\->\fIcurrent_form()\fP"
.IX Subsection "$mech->current_form()"
Returns the current form as an HTML::Form object.
.ie n .SS "$mech\->\fIlinks()\fP"
.el .SS "\f(CW$mech\fP\->\fIlinks()\fP"
.IX Subsection "$mech->links()"
When called in a list context, returns a list of the links found in the
last fetched page. In a scalar context it returns a reference to an array
with those links. Each link is a WWW::Mechanize::Link object.
.ie n .SS "$mech\->\fIis_html()\fP"
.el .SS "\f(CW$mech\fP\->\fIis_html()\fP"
.IX Subsection "$mech->is_html()"
Returns true/false on whether our content is \s-1HTML,\s0 according to the
\&\s-1HTTP\s0 headers.
.ie n .SS "$mech\->\fItitle()\fP"
.el .SS "\f(CW$mech\fP\->\fItitle()\fP"
.IX Subsection "$mech->title()"
Returns the contents of the \f(CW\*(C`\*(C'\fR tag, as parsed by
HTML::HeadParser. Returns undef if the content is not \s-1HTML.\s0
.SH "CONTENT-HANDLING METHODS"
.IX Header "CONTENT-HANDLING METHODS"
.ie n .SS "$mech\->content(...)"
.el .SS "\f(CW$mech\fP\->content(...)"
.IX Subsection "$mech->content(...)"
Returns the content that the mech uses internally for the last page
fetched. Ordinarily this is the same as
\&\f(CW\*(C`$mech\->response()\->decoded_content()\*(C'\fR,
but this may differ for \s-1HTML\s0 documents if \*(L"update_html\*(R" is
overloaded (in which case the value passed to the base-class
implementation of same will be returned), and/or extra named arguments
are passed to \fI\fIcontent()\fI\fR:
.ie n .IP "\fI\fI$mech\fI\->content( format => 'text' )\fR" 2
.el .IP "\fI\f(CI$mech\fI\->content( format => 'text' )\fR" 2
.IX Item "$mech->content( format => 'text' )"
Returns a text-only version of the page, with all \s-1HTML\s0 markup
stripped. This feature requires \fIHTML::TreeBuilder\fR to be installed,
or a fatal error will be thrown. This works only if the contents are
\&\s-1HTML.\s0
.ie n .IP "\fI\fI$mech\fI\->content( base_href => [$base_href|undef] )\fR" 2
.el .IP "\fI\f(CI$mech\fI\->content( base_href => [$base_href|undef] )\fR" 2
.IX Item "$mech->content( base_href => [$base_href|undef] )"
Returns the \s-1HTML\s0 document, modified to contain a
\&\f(CW\*(C`\*(C'\fR mark-up in the header.
\&\fI\f(CI$base_href\fI\fR is \f(CW\*(C`$mech\->base()\*(C'\fR if not specified. This is
handy to pass the \s-1HTML\s0 to e.g. HTML::Display. This works only if
the contents are \s-1HTML.\s0
.ie n .IP "\fI\fI$mech\fI\->content( raw => 1 )\fR" 2
.el .IP "\fI\f(CI$mech\fI\->content( raw => 1 )\fR" 2
.IX Item "$mech->content( raw => 1 )"
Returns \f(CW\*(C`$self\->response()\->content()\*(C'\fR, i.e. the raw contents from the
response.
.ie n .IP "\fI\fI$mech\fI\->content( decoded_by_headers => 1 )\fR" 2
.el .IP "\fI\f(CI$mech\fI\->content( decoded_by_headers => 1 )\fR" 2
.IX Item "$mech->content( decoded_by_headers => 1 )"
Returns the content after applying all \f(CW\*(C`Content\-Encoding\*(C'\fR headers but
with not additional mangling.
.ie n .IP "\fI\fI$mech\fI\->content( charset => \f(CI$charset\fI )\fR" 2
.el .IP "\fI\f(CI$mech\fI\->content( charset => \f(CI$charset\fI )\fR" 2
.IX Item "$mech->content( charset => $charset )"
Returns \f(CW\*(C`$self\->response()\->decoded_content(charset => $charset)\*(C'\fR
(see HTTP::Response for details).
.PP
To preserve backwards compatibility, additional parameters will be
ignored unless none of \f(CW\*(C`raw | decoded_by_headers | charset\*(C'\fR is
specified and the text is \s-1HTML,\s0 in which case an error will be triggered.
.ie n .SS "$mech\->\fItext()\fP"
.el .SS "\f(CW$mech\fP\->\fItext()\fP"
.IX Subsection "$mech->text()"
Returns the text of the current \s-1HTML\s0 content. If the content isn't
\&\s-1HTML,\s0 \f(CW$mech\fR will die.
.PP
The text is extracted by parsing the content, and then the extracted
text is cached, so don't worry about performance of calling this
repeatedly.
.SH "LINK METHODS"
.IX Header "LINK METHODS"
.ie n .SS "$mech\->\fIlinks()\fP"
.el .SS "\f(CW$mech\fP\->\fIlinks()\fP"
.IX Subsection "$mech->links()"
Lists all the links on the current page. Each link is a
WWW::Mechanize::Link object. In list context, returns a list of all
links. In scalar context, returns an array reference of all links.
.ie n .SS "$mech\->follow_link(...)"
.el .SS "\f(CW$mech\fP\->follow_link(...)"
.IX Subsection "$mech->follow_link(...)"
Follows a specified link on the page. You specify the match to be
found using the same parms that \f(CW\*(C`find_link()\*(C'\fR uses.
.PP
Here some examples:
.IP "\(bu" 4
3rd link called \*(L"download\*(R"
.Sp
.Vb 1
\& $mech\->follow_link( text => \*(Aqdownload\*(Aq, n => 3 );
.Ve
.IP "\(bu" 4
first link where the \s-1URL\s0 has \*(L"download\*(R" in it, regardless of case:
.Sp
.Vb 1
\& $mech\->follow_link( url_regex => qr/download/i );
.Ve
.Sp
or
.Sp
.Vb 1
\& $mech\->follow_link( url_regex => qr/(?i:download)/ );
.Ve
.IP "\(bu" 4
3rd link on the page
.Sp
.Vb 1
\& $mech\->follow_link( n => 3 );
.Ve
.IP "\(bu" 4
the link with the url
.Sp
.Vb 1
\& $mech\->follow_link( url => \*(Aq/other/page\*(Aq );
.Ve
.Sp
or
.Sp
.Vb 1
\& $mech\->follow_link( url => \*(Aqhttp://example.com/page\*(Aq );
.Ve
.PP
Returns the result of the \s-1GET\s0 method (an HTTP::Response object) if
a link was found. If the page has no links, or the specified link
couldn't be found, returns undef.
.ie n .SS "$mech\->find_link( ... )"
.el .SS "\f(CW$mech\fP\->find_link( ... )"
.IX Subsection "$mech->find_link( ... )"
Finds a link in the currently fetched page. It returns a
WWW::Mechanize::Link object which describes the link. (You'll
probably be most interested in the \f(CW\*(C`url()\*(C'\fR property.) If it fails
to find a link it returns undef.
.PP
You can take the \s-1URL\s0 part and pass it to the \f(CW\*(C`get()\*(C'\fR method. If
that's your plan, you might as well use the \f(CW\*(C`follow_link()\*(C'\fR method
directly, since it does the \f(CW\*(C`get()\*(C'\fR for you automatically.
.PP
Note that \f(CW\*(C`\*(C'\fR tags are parsed out of the the \s-1HTML\s0
and treated as links so this method works with them.
.PP
You can select which link to find by passing in one or more of these
key/value pairs:
.IP "\(bu" 4
\&\f(CW\*(C`text => \*(Aqstring\*(Aq,\*(C'\fR and \f(CW\*(C`text_regex => qr/regex/,\*(C'\fR
.Sp
\&\f(CW\*(C`text\*(C'\fR matches the text of the link against \fIstring\fR, which must be an
exact match. To select a link with text that is exactly \*(L"download\*(R", use
.Sp
.Vb 1
\& $mech\->find_link( text => \*(Aqdownload\*(Aq );
.Ve
.Sp
\&\f(CW\*(C`text_regex\*(C'\fR matches the text of the link against \fIregex\fR. To select a
link with text that has \*(L"download\*(R" anywhere in it, regardless of case, use
.Sp
.Vb 1
\& $mech\->find_link( text_regex => qr/download/i );
.Ve
.Sp
Note that the text extracted from the page's links are trimmed. For
example, \f(CW\*(C` foo \*(C'\fR is stored as 'foo', and searching for
leading or trailing spaces will fail.
.IP "\(bu" 4
\&\f(CW\*(C`url => \*(Aqstring\*(Aq,\*(C'\fR and \f(CW\*(C`url_regex => qr/regex/,\*(C'\fR
.Sp
Matches the \s-1URL\s0 of the link against \fIstring\fR or \fIregex\fR, as appropriate.
The \s-1URL\s0 may be a relative \s-1URL,\s0 like \fIfoo/bar.html\fR, depending on how
it's coded on the page.
.IP "\(bu" 4
\&\f(CW\*(C`url_abs => string\*(C'\fR and \f(CW\*(C`url_abs_regex => regex\*(C'\fR
.Sp
Matches the absolute \s-1URL\s0 of the link against \fIstring\fR or \fIregex\fR,
as appropriate. The \s-1URL\s0 will be an absolute \s-1URL,\s0 even if it's relative
in the page.
.IP "\(bu" 4
\&\f(CW\*(C`name => string\*(C'\fR and \f(CW\*(C`name_regex => regex\*(C'\fR
.Sp
Matches the name of the link against \fIstring\fR or \fIregex\fR, as appropriate.
.IP "\(bu" 4
\&\f(CW\*(C`id => string\*(C'\fR and \f(CW\*(C`id_regex => regex\*(C'\fR
.Sp
Matches the attribute 'id' of the link against \fIstring\fR or
\&\fIregex\fR, as appropriate.
.IP "\(bu" 4
\&\f(CW\*(C`class => string\*(C'\fR and \f(CW\*(C`class_regex => regex\*(C'\fR
.Sp
Matches the attribute 'class' of the link against \fIstring\fR or
\&\fIregex\fR, as appropriate.
.IP "\(bu" 4
\&\f(CW\*(C`tag => string\*(C'\fR and \f(CW\*(C`tag_regex => regex\*(C'\fR
.Sp
Matches the tag that the link came from against \fIstring\fR or \fIregex\fR,
as appropriate. The \f(CW\*(C`tag_regex\*(C'\fR is probably most useful to check for
more than one tag, as in:
.Sp
.Vb 1
\& $mech\->find_link( tag_regex => qr/^(a|frame)$/ );
.Ve
.Sp
The tags and attributes looked at are defined below, at
\&\*(L"$mech\->\fIfind_link()\fR : link format\*(R".
.PP
If \f(CW\*(C`n\*(C'\fR is not specified, it defaults to 1. Therefore, if you don't
specify any parms, this method defaults to finding the first link on the
page.
.PP
Note that you can specify multiple text or \s-1URL\s0 parameters, which
will be ANDed together. For example, to find the first link with
text of \*(L"News\*(R" and with \*(L"cnn.com\*(R" in the \s-1URL,\s0 use:
.PP
.Vb 1
\& $mech\->find_link( text => \*(AqNews\*(Aq, url_regex => qr/cnn\e.com/ );
.Ve
.PP
The return value is a reference to an array containing a
WWW::Mechanize::Link object for every link in \f(CW\*(C`$self\->content\*(C'\fR.
.PP
The links come from the following:
.ie n .IP """""" 4
.el .IP "\f(CW\fR" 4
.IX Item ""
.PD 0
.ie n .IP """""" 4
.el .IP "\f(CW\fR" 4
.IX Item ""
.ie n .IP """""" 4
.el .IP "\f(CW\fR" 4
.IX Item ""
.ie n .IP """