Gestionnaire de fichiers - Editer - /usr/local/share/man/man3/WWW::Mechanize.3pm
Arrière
.\" 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 "2020-02-20" "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.96 .SH "SYNOPSIS" .IX Header "SYNOPSIS" WWW::Mechanize 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 \& ); \& \& # Enable strict form processing to catch typos and non\-existant form fields. \& my $strict_mech = WWW::Mechanize\->new( strict_forms => 1); \& \& $strict_mech\->get( $url ); \& \& # This method call will die, saving you lots of time looking for the bug. \& $strict_mech\->submit_form( \& form_number => 3, \& fields => { \& usernaem => \*(Aqmungo\*(Aq, # typo in field name \& password => \*(Aqlost\-and\-alone\*(Aq, \& extra_field => 123, # field does not exist \& } \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\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 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 <https://github.com/libwww\-perl/WWW\-Mechanize/issues> .Sp The queue for bugs & enhancements in WWW::Mechanize. Please note that the queue at <http://rt.cpan.org> is no longer maintained. .IP "\(bu" 4 <https://metacpan.org/pod/WWW::Mechanize> .Sp The \s-1CPAN\s0 documentation page for Mechanize. .IP "\(bu" 4 <https://metacpan.org/pod/distribution/WWW\-Mechanize/lib/WWW/Mechanize/FAQ.pod> .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::Mechanize instances 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 In addition, WWW::Mechanize also allows you to globally enable strict and verbose mode for form handling, which is done with HTML::Form. .IP "\(bu" 4 \&\f(CW\*(C`strict_forms => [0|1]\*(C'\fR .Sp Globally sets the HTML::Form strict flag which causes form submission to croak if any of the passed fields don't exist in the form, and/or a value doesn't exist in a select element. This can still be disabled in individual calls to \f(CW\*(C`submit_form()\*(C'\fR. .Sp Default is off. .IP "\(bu" 4 \&\f(CW\*(C`verbose_forms => [0|1]\*(C'\fR .Sp Globally sets the HTML::Form verbose flag which causes form submission to warn about any bad \s-1HTML\s0 form constructs found. This cannot be disabled later. .Sp Default is off. .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\->post( $uri, content => $content )" .el .SS "\f(CW$mech\fP\->post( \f(CW$uri\fP, content => \f(CW$content\fP )" .IX Subsection "$mech->post( $uri, content => $content )" POSTs \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\->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 \fIback()\fR 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\->\fIclear_history()\fP" .el .SS "\f(CW$mech\fP\->\fIclear_history()\fP" .IX Subsection "$mech->clear_history()" This deletes all the history entries and returns true. .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`<TITLE>\*(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 update_html 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 version 5 or higher 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`<base href="$base_href">\*(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 \f(CW\*(C`GET\*(C'\fR method (an HTTP::Response object) if a link was found. .PP If the page has no links, or the specified link couldn't be found, returns \&\f(CW\*(C`undef\*(C'\fR. If \f(CW\*(C`autocheck\*(C'\fR is enabled an exception will be thrown instead. .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`<FRAME SRC="...">\*(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`<a> foo </a>\*(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. .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 """<a href=...>""" 4 .el .IP "\f(CW<a href=...>\fR" 4 .IX Item "<a href=...>" .PD 0 .ie n .IP """<area href=...>""" 4 .el .IP "\f(CW<area href=...>\fR" 4 .IX Item "<area href=...>" .ie n .IP """<frame src=...>""" 4 .el .IP "\f(CW<frame src=...>\fR" 4 .IX Item "<frame src=...>" .ie n .IP """<iframe src=...>""" 4 .el .IP "\f(CW<iframe src=...>\fR" 4 .IX Item "<iframe src=...>" .ie n .IP """<link href=...>""" 4 .el .IP "\f(CW<link href=...>\fR" 4 .IX Item "<link href=...>" .ie n .IP """<meta content=...>""" 4 .el .IP "\f(CW<meta content=...>\fR" 4 .IX Item "<meta content=...>" .PD .ie n .SS "$mech\->find_all_links( ... )" .el .SS "\f(CW$mech\fP\->find_all_links( ... )" .IX Subsection "$mech->find_all_links( ... )" Returns all the links on the current page that match the criteria. The method for specifying link criteria is the same as in \&\f(CW\*(C`find_link()\*(C'\fR. Each of the links returned is a WWW::Mechanize::Link object. .PP In list context, \f(CW\*(C`find_all_links()\*(C'\fR returns a list of the links. Otherwise, it returns a reference to the list of links. .PP \&\f(CW\*(C`find_all_links()\*(C'\fR with no parameters returns all links in the page. .ie n .SS "$mech\->find_all_inputs( ... criteria ... )" .el .SS "\f(CW$mech\fP\->find_all_inputs( ... criteria ... )" .IX Subsection "$mech->find_all_inputs( ... criteria ... )" \&\fIfind_all_inputs()\fR returns an array of all the input controls in the current form whose properties match all of the regexes passed in. The controls returned are all descended from HTML::Form::Input. See \*(L"\s-1INPUTS\*(R"\s0 in HTML::Form for details. .PP If no criteria are passed, all inputs will be returned. .PP If there is no current page, there is no form on the current page, or there are no submit controls in the current form then the return will be an empty array. .PP You may use a regex or a literal string: .PP .Vb 5 \& # get all textarea controls whose names begin with "customer" \& my @customer_text_inputs = $mech\->find_all_inputs( \& type => \*(Aqtextarea\*(Aq, \& name_regex => qr/^customer/, \& ); \& \& # get all text or textarea controls called "customer" \& my @customer_text_inputs = $mech\->find_all_inputs( \& type_regex => qr/^(text|textarea)$/, \& name => \*(Aqcustomer\*(Aq, \& ); .Ve .ie n .SS "$mech\->find_all_submits( ... criteria ... )" .el .SS "\f(CW$mech\fP\->find_all_submits( ... criteria ... )" .IX Subsection "$mech->find_all_submits( ... criteria ... )" \&\f(CW\*(C`find_all_submits()\*(C'\fR does the same thing as \f(CW\*(C`find_all_inputs()\*(C'\fR except that it only returns controls that are submit controls, ignoring other types of input controls like text and checkboxes. .SH "IMAGE METHODS" .IX Header "IMAGE METHODS" .ie n .SS "$mech\->images" .el .SS "\f(CW$mech\fP\->images" .IX Subsection "$mech->images" Lists all the images on the current page. Each image is a WWW::Mechanize::Image object. In list context, returns a list of all images. In scalar context, returns an array reference of all images. .ie n .SS "$mech\->\fIfind_image()\fP" .el .SS "\f(CW$mech\fP\->\fIfind_image()\fP" .IX Subsection "$mech->find_image()" Finds an image in the current page. It returns a WWW::Mechanize::Image object which describes the image. If it fails to find an image it returns undef. .PP You can select which image to find by passing in one or more of these key/value pairs: .IP "\(bu" 4 \&\f(CW\*(C`alt => \*(Aqstring\*(Aq\*(C'\fR and \f(CW\*(C`alt_regex => qr/regex/\*(C'\fR .Sp \&\f(CW\*(C`alt\*(C'\fR matches the \s-1ALT\s0 attribute of the image against \fIstring\fR, which must be an exact match. To select a image with an \s-1ALT\s0 tag that is exactly \*(L"download\*(R", use .Sp .Vb 1 \& $mech\->find_image( alt => \*(Aqdownload\*(Aq ); .Ve .Sp \&\f(CW\*(C`alt_regex\*(C'\fR matches the \s-1ALT\s0 attribute of the image against a regular expression. To select an image with an \s-1ALT\s0 attribute that has \*(L"download\*(R" anywhere in it, regardless of case, use .Sp .Vb 1 \& $mech\->find_image( alt_regex => qr/download/i ); .Ve .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 image 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 image 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`tag => string\*(C'\fR and \f(CW\*(C`tag_regex => regex\*(C'\fR .Sp Matches the tag that the image 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_image( tag_regex => qr/^(img|input)$/ ); .Ve .Sp The tags supported are \f(CW\*(C`<img>\*(C'\fR and \f(CW\*(C`<input>\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`id => string\*(C'\fR and \f(CW\*(C`id_regex => regex\*(C'\fR .Sp \&\f(CW\*(C`id\*(C'\fR matches the id attribute of the image against \fIstring\fR, which must be an exact match. To select an image with the exact id \*(L"download-image\*(R", use .Sp .Vb 1 \& $mech\->find_image( id => \*(Aqdownload\-image\*(Aq ); .Ve .Sp \&\f(CW\*(C`id_regex\*(C'\fR matches the id attribute of the image against a regular expression. To select the first image with an id that contains \*(L"download\*(R" anywhere in it, use .Sp .Vb 1 \& $mech\->find_image( id_regex => qr/download/ ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`classs => string\*(C'\fR and \f(CW\*(C`class_regex => regex\*(C'\fR .Sp \&\f(CW\*(C`class\*(C'\fR matches the class attribute of the image against \fIstring\fR, which must be an exact match. To select an image with the exact class \*(L"img-fuid\*(R", use .Sp .Vb 1 \& $mech\->find_image( class => \*(Aqimg\-fluid\*(Aq ); .Ve .Sp To select an image with the class attribute \*(L"rounded float-left\*(R", use .Sp .Vb 1 \& $mech\->find_image( class => \*(Aqrounded float\-left\*(Aq ); .Ve .Sp Note that the classes have to be matched as a complete string, in the exact order they appear in the website's source code. .Sp \&\f(CW\*(C`class_regex\*(C'\fR matches the class attribute of the image against a regular expression. Use this if you want a partial class name, or if an image has several classes, but you only care about one. .Sp To select the first image with the class \*(L"rounded\*(R", where there are multiple images that might also have either class \*(L"float-left\*(R" or \*(L"float-right\*(R", use .Sp .Vb 1 \& $mech\->find_image( class_regex => qr/\ebrounded\eb/ ); .Ve .Sp Selecting an image with multiple classes where you do not care about the order they appear in the website's source code is not currently supported. .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 image on the page. .PP Note that you can specify multiple \s-1ALT\s0 or \s-1URL\s0 parameters, which will be ANDed together. For example, to find the first image with \&\s-1ALT\s0 text of \*(L"News\*(R" and with \*(L"cnn.com\*(R" in the \s-1URL,\s0 use: .PP .Vb 1 \& $mech\->find_image( image => \*(AqNews\*(Aq, url_regex => qr/cnn\e.com/ ); .Ve .PP The return value is a reference to an array containing a WWW::Mechanize::Image object for every image in \f(CW\*(C`$self\->content\*(C'\fR. .ie n .SS "$mech\->find_all_images( ... )" .el .SS "\f(CW$mech\fP\->find_all_images( ... )" .IX Subsection "$mech->find_all_images( ... )" Returns all the images on the current page that match the criteria. The method for specifying image criteria is the same as in \&\f(CW\*(C`find_image()\*(C'\fR. Each of the images returned is a WWW::Mechanize::Image object. .PP In list context, \f(CW\*(C`find_all_images()\*(C'\fR returns a list of the images. Otherwise, it returns a reference to the list of images. .PP \&\f(CW\*(C`find_all_images()\*(C'\fR with no parameters returns all images in the page. .SH "FORM METHODS" .IX Header "FORM METHODS" These methods let you work with the forms on a page. The idea is to choose a form that you'll later work with using the field methods below. .ie n .SS "$mech\->forms" .el .SS "\f(CW$mech\fP\->forms" .IX Subsection "$mech->forms" Lists all the forms on the current page. Each form is an HTML::Form object. In list context, returns a list of all forms. In scalar context, returns an array reference of all forms. .ie n .SS "$mech\->form_number($number)" .el .SS "\f(CW$mech\fP\->form_number($number)" .IX Subsection "$mech->form_number($number)" Selects the \fInumber\fRth form on the page as the target for subsequent calls to \f(CW\*(C`field()\*(C'\fR and \f(CW\*(C`click()\*(C'\fR. Also returns the form that was selected. .PP If it is found, the form is returned as an HTML::Form object and set internally for later use with Mech's form methods such as \&\f(CW\*(C`field()\*(C'\fR and \&\f(CW\*(C`click()\*(C'\fR. When called in a list context, the number of the found form is also returned as a second value. .PP Emits a warning and returns undef if no form is found. .PP The first form is number 1, not zero. .ie n .SS "$mech\->form_name( $name )" .el .SS "\f(CW$mech\fP\->form_name( \f(CW$name\fP )" .IX Subsection "$mech->form_name( $name )" Selects a form by name. If there is more than one form on the page with that name, then the first one is used, and a warning is generated. .PP If it is found, the form is returned as an HTML::Form object and set internally for later use with Mech's form methods such as \&\f(CW\*(C`field()\*(C'\fR and \&\f(CW\*(C`click()\*(C'\fR. .PP Returns undef if no form is found. .ie n .SS "$mech\->form_id( $name )" .el .SS "\f(CW$mech\fP\->form_id( \f(CW$name\fP )" .IX Subsection "$mech->form_id( $name )" Selects a form by \s-1ID. \s0 If there is more than one form on the page with that \s-1ID,\s0 then the first one is used, and a warning is generated. .PP If it is found, the form is returned as an HTML::Form object and set internally for later use with Mech's form methods such as \&\f(CW\*(C`field()\*(C'\fR and \&\f(CW\*(C`click()\*(C'\fR. .PP If no form is found it returns \f(CW\*(C`undef\*(C'\fR. This will also trigger a warning, unless \f(CW\*(C`quiet\*(C'\fR is enabled. .ie n .SS "$mech\->all_forms_with_fields( @fields )" .el .SS "\f(CW$mech\fP\->all_forms_with_fields( \f(CW@fields\fP )" .IX Subsection "$mech->all_forms_with_fields( @fields )" Selects a form by passing in a list of field names it must contain. All matching forms (perhaps none) are returned as a list of HTML::Form objects. .ie n .SS "$mech\->form_with_fields( @fields )" .el .SS "\f(CW$mech\fP\->form_with_fields( \f(CW@fields\fP )" .IX Subsection "$mech->form_with_fields( @fields )" Selects a form by passing in a list of field names it must contain. If there is more than one form on the page with that matches, then the first one is used, and a warning is generated. .PP If it is found, the form is returned as an HTML::Form object and set internally for later used with Mech's form methods such as \&\f(CW\*(C`field()\*(C'\fR and \&\f(CW\*(C`click()\*(C'\fR. .PP Returns undef and emits a warning if no form is found. .PP Note that this functionality requires libwww-perl 5.69 or higher. .ie n .SS "$mech\->all_forms_with( $attr1 => $value1, $attr2 => $value2, ... )" .el .SS "\f(CW$mech\fP\->all_forms_with( \f(CW$attr1\fP => \f(CW$value1\fP, \f(CW$attr2\fP => \f(CW$value2\fP, ... )" .IX Subsection "$mech->all_forms_with( $attr1 => $value1, $attr2 => $value2, ... )" Searches for forms with arbitrary attribute/value pairs within the <form> tag. (Currently does not work for attribute \f(CW\*(C`action\*(C'\fR due to implementation details of HTML::Form.) When given more than one pair, all criteria must match. Using \f(CW\*(C`undef\*(C'\fR as value means that the attribute in question must not be present. .PP All matching forms (perhaps none) are returned as a list of HTML::Form objects. .ie n .SS "$mech\->form_with( $attr1 => $value1, $attr2 => $value2, ... )" .el .SS "\f(CW$mech\fP\->form_with( \f(CW$attr1\fP => \f(CW$value1\fP, \f(CW$attr2\fP => \f(CW$value2\fP, ... )" .IX Subsection "$mech->form_with( $attr1 => $value1, $attr2 => $value2, ... )" Searches for forms with arbitrary attribute/value pairs within the <form> tag. (Currently does not work for attribute \f(CW\*(C`action\*(C'\fR due to implementation details of HTML::Form.) When given more than one pair, all criteria must match. Using \f(CW\*(C`undef\*(C'\fR as value means that the attribute in question must not be present. .PP If it is found, the form is returned as an HTML::Form object and set internally for later used with Mech's form methods such as \&\f(CW\*(C`field()\*(C'\fR and \&\f(CW\*(C`click()\*(C'\fR. .PP Returns undef if no form is found. .SH "FIELD METHODS" .IX Header "FIELD METHODS" These methods allow you to set the values of fields in a given form. .ie n .SS "$mech\->field( $name, $value, $number )" .el .SS "\f(CW$mech\fP\->field( \f(CW$name\fP, \f(CW$value\fP, \f(CW$number\fP )" .IX Subsection "$mech->field( $name, $value, $number )" .ie n .SS "$mech\->field( $name, \e@values, $number )" .el .SS "\f(CW$mech\fP\->field( \f(CW$name\fP, \e@values, \f(CW$number\fP )" .IX Subsection "$mech->field( $name, @values, $number )" Given the name of a field, set its value to the value specified. This applies to the current form (as set by the \&\f(CW\*(C`form_name()\*(C'\fR or \&\f(CW\*(C`form_number()\*(C'\fR method or defaulting to the first form on the page). .PP The optional \fI\f(CI$number\fI\fR parameter is used to distinguish between two fields with the same name. The fields are numbered from 1. .ie n .SS "$mech\->select($name, $value)" .el .SS "\f(CW$mech\fP\->select($name, \f(CW$value\fP)" .IX Subsection "$mech->select($name, $value)" .ie n .SS "$mech\->select($name, \e@values)" .el .SS "\f(CW$mech\fP\->select($name, \e@values)" .IX Subsection "$mech->select($name, @values)" Given the name of a \f(CW\*(C`select\*(C'\fR field, set its value to the value specified. If the field is not \f(CW\*(C`<select multiple>\*(C'\fR and the \&\f(CW$value\fR is an array, only the \fBfirst\fR value will be set. [Note: the documentation previously claimed that only the last value would be set, but this was incorrect.] Passing \f(CW$value\fR as a hash with an \f(CW\*(C`n\*(C'\fR key selects an item by number (e.g. \&\f(CW\*(C`{n => 3}\*(C'\fR or \f(CW\*(C`{n => [2,4]}\*(C'\fR). The numbering starts at 1. This applies to the current form. .PP If you have a field with \f(CW\*(C`<select multiple>\*(C'\fR and you pass a single \&\f(CW$value\fR, then \f(CW$value\fR will be added to the list of fields selected, without clearing the others. However, if you pass an array reference, then all previously selected values will be cleared. .PP Returns true on successfully setting the value. On failure, returns false and calls \f(CW\*(C`$self\->warn()\*(C'\fR with an error message. .ie n .SS "$mech\->set_fields( $name => $value ... )" .el .SS "\f(CW$mech\fP\->set_fields( \f(CW$name\fP => \f(CW$value\fP ... )" .IX Subsection "$mech->set_fields( $name => $value ... )" This method sets multiple fields of the current form. It takes a list of field name and value pairs. If there is more than one field with the same name, the first one found is set. If you want to select which of the duplicate field to set, use a value which is an anonymous array which has the field value and its number as the 2 elements. .PP .Vb 2 \& # set the second foo field \& $mech\->set_fields( $name => [ \*(Aqfoo\*(Aq, 2 ] ); .Ve .PP The fields are numbered from 1. .PP This applies to the current form. .ie n .SS "$mech\->set_visible( @criteria )" .el .SS "\f(CW$mech\fP\->set_visible( \f(CW@criteria\fP )" .IX Subsection "$mech->set_visible( @criteria )" This method sets fields of the current form without having to know their names. So if you have a login screen that wants a username and password, you do not have to fetch the form and inspect the source (or use the \fImech-dump\fR utility, installed with WWW::Mechanize) to see what the field names are; you can just say .PP .Vb 1 \& $mech\->set_visible( $username, $password ); .Ve .PP and the first and second fields will be set accordingly. The method is called set_\fIvisible\fR because it acts only on visible fields; hidden form inputs are not considered. The order of the fields is the order in which they appear in the \s-1HTML\s0 source which is nearly always the order anyone viewing the page would think they are in, but some creative work with tables could change that; caveat user. .PP Each element in \f(CW@criteria\fR is either a field value or a field specifier. A field value is a scalar. A field specifier allows you to specify the \fItype\fR of input field you want to set and is denoted with an arrayref containing two elements. So you could specify the first radio button with .PP .Vb 1 \& $mech\->set_visible( [ radio => \*(AqKCRW\*(Aq ] ); .Ve .PP Field values and specifiers can be intermixed, hence .PP .Vb 1 \& $mech\->set_visible( \*(Aqfred\*(Aq, \*(Aqsecret\*(Aq, [ option => \*(AqChecking\*(Aq ] ); .Ve .PP would set the first two fields to \*(L"fred\*(R" and \*(L"secret\*(R", and the \fInext\fR \&\f(CW\*(C`OPTION\*(C'\fR menu field to \*(L"Checking\*(R". .PP The possible field specifier types are: \*(L"text\*(R", \*(L"password\*(R", \*(L"hidden\*(R", \&\*(L"textarea\*(R", \*(L"file\*(R", \*(L"image\*(R", \*(L"submit\*(R", \*(L"radio\*(R", \*(L"checkbox\*(R" and \*(L"option\*(R". .PP \&\f(CW\*(C`set_visible\*(C'\fR returns the number of values set. .ie n .SS "$mech\->tick( $name, $value [, $set] )" .el .SS "\f(CW$mech\fP\->tick( \f(CW$name\fP, \f(CW$value\fP [, \f(CW$set\fP] )" .IX Subsection "$mech->tick( $name, $value [, $set] )" \&\*(L"Ticks\*(R" the first checkbox that has both the name and value associated with it on the current form. Dies if there is no named check box for that value. Passing in a false value as the third optional argument will cause the checkbox to be unticked. .ie n .SS "$mech\->untick($name, $value)" .el .SS "\f(CW$mech\fP\->untick($name, \f(CW$value\fP)" .IX Subsection "$mech->untick($name, $value)" Causes the checkbox to be unticked. Shorthand for \&\f(CW\*(C`tick($name,$value,undef)\*(C'\fR .ie n .SS "$mech\->value( $name [, $number] )" .el .SS "\f(CW$mech\fP\->value( \f(CW$name\fP [, \f(CW$number\fP] )" .IX Subsection "$mech->value( $name [, $number] )" Given the name of a field, return its value. This applies to the current form. .PP The optional \fI\f(CI$number\fI\fR parameter is used to distinguish between two fields with the same name. The fields are numbered from 1. .PP If the field is of type file (file upload field), the value is always cleared to prevent remote sites from downloading your local files. To upload a file, specify its file name explicitly. .ie n .SS "$mech\->click( $button [, $x, $y] )" .el .SS "\f(CW$mech\fP\->click( \f(CW$button\fP [, \f(CW$x\fP, \f(CW$y\fP] )" .IX Subsection "$mech->click( $button [, $x, $y] )" Has the effect of clicking a button on the current form. The first argument is the name of the button to be clicked. The second and third arguments (optional) allow you to specify the (x,y) coordinates of the click. .PP If there is only one button on the form, \f(CW\*(C`$mech\->click()\*(C'\fR with no arguments simply clicks that one button. .PP Returns an HTTP::Response object. .ie n .SS "$mech\->click_button( ... )" .el .SS "\f(CW$mech\fP\->click_button( ... )" .IX Subsection "$mech->click_button( ... )" Has the effect of clicking a button on the current form by specifying its name, value, or index. Its arguments are a list of key/value pairs. Only one of name, number, input or value must be specified in the keys. .IP "\(bu" 4 \&\f(CW\*(C`name => name\*(C'\fR .Sp Clicks the button named \fIname\fR in the current form. .IP "\(bu" 4 \&\f(CW\*(C`id => id\*(C'\fR .Sp Clicks the button with the id \fIid\fR in the current form. .IP "\(bu" 4 \&\f(CW\*(C`number => n\*(C'\fR .Sp Clicks the \fIn\fRth button in the current form. Numbering starts at 1. .IP "\(bu" 4 \&\f(CW\*(C`value => value\*(C'\fR .Sp Clicks the button with the value \fIvalue\fR in the current form. .IP "\(bu" 4 \&\f(CW\*(C`input => $inputobject\*(C'\fR .Sp Clicks on the button referenced by \f(CW$inputobject\fR, an instance of HTML::Form::SubmitInput obtained e.g. from .Sp .Vb 1 \& $mech\->current_form()\->find_input( undef, \*(Aqsubmit\*(Aq ) .Ve .Sp \&\f(CW$inputobject\fR must belong to the current form. .IP "\(bu" 4 \&\f(CW\*(C`x => x\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`y => y\*(C'\fR .Sp These arguments (optional) allow you to specify the (x,y) coordinates of the click. .ie n .SS "$mech\->\fIsubmit()\fP" .el .SS "\f(CW$mech\fP\->\fIsubmit()\fP" .IX Subsection "$mech->submit()" Submits the current form, without specifying a button to click. Actually, no button is clicked at all. .PP Returns an HTTP::Response object. .PP This used to be a synonym for \f(CW\*(C`$mech\->click( \*(Aqsubmit\*(Aq )\*(C'\fR, but is no longer so. .ie n .SS "$mech\->submit_form( ... )" .el .SS "\f(CW$mech\fP\->submit_form( ... )" .IX Subsection "$mech->submit_form( ... )" This method lets you select a form from the previously fetched page, fill in its fields, and submit it. It combines the \f(CW\*(C`form_number\*(C'\fR/\f(CW\*(C`form_name\*(C'\fR, \&\f(CW\*(C`set_fields\*(C'\fR and \f(CW\*(C`click\*(C'\fR methods into one higher level call. Its arguments are a list of key/value pairs, all of which are optional. .IP "\(bu" 4 \&\f(CW\*(C`fields => \e%fields\*(C'\fR .Sp Specifies the fields to be filled in the current form. .IP "\(bu" 4 \&\f(CW\*(C`with_fields => \e%fields\*(C'\fR .Sp Probably all you need for the common case. It combines a smart form selector and data setting in one operation. It selects the first form that contains all fields mentioned in \f(CW\*(C`\e%fields\*(C'\fR. This is nice because you don't need to know the name or number of the form to do this. .Sp (calls \f(CW\*(C`form_with_fields()\*(C'\fR and \f(CW\*(C`set_fields()\*(C'\fR). .Sp If you choose \f(CW\*(C`with_fields\*(C'\fR, the \f(CW\*(C`fields\*(C'\fR option will be ignored. The \&\f(CW\*(C`form_number\*(C'\fR, \f(CW\*(C`form_name\*(C'\fR and \f(CW\*(C`form_id\*(C'\fR options will still be used. An exception will be thrown unless exactly one form matches all of the provided criteria. .IP "\(bu" 4 \&\f(CW\*(C`form_number => n\*(C'\fR .Sp Selects the \fIn\fRth form (calls \&\f(CW\*(C`form_number()\*(C'\fR. If this parm is not specified, the currently-selected form is used. .IP "\(bu" 4 \&\f(CW\*(C`form_name => name\*(C'\fR .Sp Selects the form named \fIname\fR (calls \&\f(CW\*(C`form_name()\*(C'\fR) .IP "\(bu" 4 \&\f(CW\*(C`form_id => ID\*(C'\fR .Sp Selects the form with \s-1ID \s0\fI\s-1ID\s0\fR (calls \&\f(CW\*(C`form_id()\*(C'\fR) .IP "\(bu" 4 \&\f(CW\*(C`button => button\*(C'\fR .Sp Clicks on button \fIbutton\fR (calls \f(CW\*(C`click()\*(C'\fR) .IP "\(bu" 4 \&\f(CW\*(C`x => x, y => y\*(C'\fR .Sp Sets the x or y values for \f(CW\*(C`click()\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`strict_forms => bool\*(C'\fR .Sp Sets the HTML::Form strict flag which causes form submission to croak if any of the passed fields don't exist on the page, and/or a value doesn't exist in a select element. By default HTML::Form sets this value to false. .Sp This behavior can also be turned on globally by passing \f(CW\*(C`strict_forms => 1\*(C'\fR to \&\f(CW\*(C`WWW::Mechanize\->new\*(C'\fR. If you do that, you can still disable it for individual calls by passing \f(CW\*(C`strict_forms => 0\*(C'\fR here. .PP If no form is selected, the first form found is used. .PP If \fIbutton\fR is not passed, then the \f(CW\*(C`submit()\*(C'\fR method is used instead. .PP If you want to submit a file and get its content from a scalar rather than a file in the filesystem, you can use: .PP .Vb 1 \& $mech\->submit_form(with_fields => { logfile => [ [ undef, \*(Aqwhatever\*(Aq, Content => $content ], 1 ] } ); .Ve .PP Returns an HTTP::Response object. .SH "MISCELLANEOUS METHODS" .IX Header "MISCELLANEOUS METHODS" .ie n .SS "$mech\->add_header( name => $value [, name => $value... ] )" .el .SS "\f(CW$mech\fP\->add_header( name => \f(CW$value\fP [, name => \f(CW$value\fP... ] )" .IX Subsection "$mech->add_header( name => $value [, name => $value... ] )" Sets \s-1HTTP\s0 headers for the agent to add or remove from the \s-1HTTP\s0 request. .PP .Vb 1 \& $mech\->add_header( Encoding => \*(Aqtext/klingon\*(Aq ); .Ve .PP If a \fIvalue\fR is \f(CW\*(C`undef\*(C'\fR, then that header will be removed from any future requests. For example, to never send a Referer header: .PP .Vb 1 \& $mech\->add_header( Referer => undef ); .Ve .PP If you want to delete a header, use \f(CW\*(C`delete_header\*(C'\fR. .PP Returns the number of name/value pairs added. .PP \&\fB\s-1NOTE\s0\fR: This method was very different in WWW::Mechanize before 1.00. Back then, the headers were stored in a package hash, not as a member of the object instance. Calling \f(CW\*(C`add_header()\*(C'\fR would modify the headers for every WWW::Mechanize object, even after your object no longer existed. .ie n .SS "$mech\->delete_header( name [, name ... ] )" .el .SS "\f(CW$mech\fP\->delete_header( name [, name ... ] )" .IX Subsection "$mech->delete_header( name [, name ... ] )" Removes \s-1HTTP\s0 headers from the agent's list of special headers. For instance, you might need to do something like: .PP .Vb 2 \& # Don\*(Aqt send a Referer for this URL \& $mech\->add_header( Referer => undef ); \& \& # Get the URL \& $mech\->get( $url ); \& \& # Back to the default behavior \& $mech\->delete_header( \*(AqReferer\*(Aq ); .Ve .ie n .SS "$mech\->quiet(true/false)" .el .SS "\f(CW$mech\fP\->quiet(true/false)" .IX Subsection "$mech->quiet(true/false)" Allows you to suppress warnings to the screen. .PP .Vb 3 \& $mech\->quiet(0); # turns on warnings (the default) \& $mech\->quiet(1); # turns off warnings \& $mech\->quiet(); # returns the current quietness status .Ve .ie n .SS "$mech\->stack_depth( $max_depth )" .el .SS "\f(CW$mech\fP\->stack_depth( \f(CW$max_depth\fP )" .IX Subsection "$mech->stack_depth( $max_depth )" Get or set the page stack depth. Use this if you're doing a lot of page scraping and running out of memory. .PP A value of 0 means \*(L"no history at all.\*(R" By default, the max stack depth is humongously large, effectively keeping all history. .ie n .SS "$mech\->save_content( $filename, %opts )" .el .SS "\f(CW$mech\fP\->save_content( \f(CW$filename\fP, \f(CW%opts\fP )" .IX Subsection "$mech->save_content( $filename, %opts )" Dumps the contents of \f(CW\*(C`$mech\->content\*(C'\fR into \fI\f(CI$filename\fI\fR. \&\fI\f(CI$filename\fI\fR will be overwritten. Dies if there are any errors. .PP If the content type does not begin with \*(L"text/\*(R", then the content is saved in binary mode (i.e. \f(CW\*(C`binmode()\*(C'\fR is set on the output filehandle). .PP Additional arguments can be passed as \fIkey\fR/\fIvalue\fR pairs: .ie n .IP "\fI\fI$mech\fI\->save_content( \f(CI$filename\fI, binary => 1 )\fR" 4 .el .IP "\fI\f(CI$mech\fI\->save_content( \f(CI$filename\fI, binary => 1 )\fR" 4 .IX Item "$mech->save_content( $filename, binary => 1 )" Filehandle is set with \f(CW\*(C`binmode\*(C'\fR to \f(CW\*(C`:raw\*(C'\fR and contents are taken calling \f(CW\*(C`$self\->content(decoded_by_headers => 1)\*(C'\fR. Same as calling: .Sp .Vb 2 \& $mech\->save_content( $filename, binmode => \*(Aq:raw\*(Aq, \& decoded_by_headers => 1 ); .Ve .Sp This \fIshould\fR be the safest way to save contents verbatim. .ie n .IP "\fI\fI$mech\fI\->save_content( \f(CI$filename\fI, binmode => \f(CI$binmode\fI )\fR" 4 .el .IP "\fI\f(CI$mech\fI\->save_content( \f(CI$filename\fI, binmode => \f(CI$binmode\fI )\fR" 4 .IX Item "$mech->save_content( $filename, binmode => $binmode )" Filehandle is set to binary mode. If \f(CW$binmode\fR begins with ':', it is passed as a parameter to \f(CW\*(C`binmode\*(C'\fR: .Sp .Vb 1 \& binmode $fh, $binmode; .Ve .Sp otherwise the filehandle is set to binary mode if \f(CW$binmode\fR is true: .Sp .Vb 1 \& binmode $fh; .Ve .IP "\fIall other arguments\fR" 4 .IX Item "all other arguments" are passed as-is to \f(CW\*(C`$mech\->content(%opts)\*(C'\fR. In particular, \&\f(CW\*(C`decoded_by_headers\*(C'\fR might come handy if you want to revert the effect of line compression performed by the web server but without further interpreting the contents (e.g. decoding it according to the charset). .ie n .SS "$mech\->dump_headers( [$fh] )" .el .SS "\f(CW$mech\fP\->dump_headers( [$fh] )" .IX Subsection "$mech->dump_headers( [$fh] )" Prints a dump of the \s-1HTTP\s0 response headers for the most recent response. If \fI\f(CI$fh\fI\fR is not specified or is undef, it dumps to \&\s-1STDOUT.\s0 .PP Unlike the rest of the dump_* methods, \f(CW$fh\fR can be a scalar. It will be used as a file name. .ie n .SS "$mech\->dump_links( [[$fh], $absolute] )" .el .SS "\f(CW$mech\fP\->dump_links( [[$fh], \f(CW$absolute\fP] )" .IX Subsection "$mech->dump_links( [[$fh], $absolute] )" Prints a dump of the links on the current page to \fI\f(CI$fh\fI\fR. If \fI\f(CI$fh\fI\fR is not specified or is undef, it dumps to \s-1STDOUT.\s0 .PP If \fI\f(CI$absolute\fI\fR is true, links displayed are absolute, not relative. .ie n .SS "$mech\->dump_images( [[$fh], $absolute] )" .el .SS "\f(CW$mech\fP\->dump_images( [[$fh], \f(CW$absolute\fP] )" .IX Subsection "$mech->dump_images( [[$fh], $absolute] )" Prints a dump of the images on the current page to \fI\f(CI$fh\fI\fR. If \fI\f(CI$fh\fI\fR is not specified or is undef, it dumps to \s-1STDOUT.\s0 .PP If \fI\f(CI$absolute\fI\fR is true, links displayed are absolute, not relative. .PP The output will include empty lines for images that have no \f(CW\*(C`src\*(C'\fR attribute and therefore no \f(CW\*(C`<\-\*(C'\fRurl>>. .ie n .SS "$mech\->dump_forms( [$fh] )" .el .SS "\f(CW$mech\fP\->dump_forms( [$fh] )" .IX Subsection "$mech->dump_forms( [$fh] )" Prints a dump of the forms on the current page to \fI\f(CI$fh\fI\fR. If \fI\f(CI$fh\fI\fR is not specified or is undef, it dumps to \s-1STDOUT.\s0 Running the following: .PP .Vb 3 \& my $mech = WWW::Mechanize\->new(); \& $mech\->get("https://www.google.com/"); \& $mech\->dump_forms; .Ve .PP will print: .PP .Vb 10 \& GET https://www.google.com/search [f] \& ie=ISO\-8859\-1 (hidden readonly) \& hl=en (hidden readonly) \& source=hp (hidden readonly) \& biw= (hidden readonly) \& bih= (hidden readonly) \& q= (text) \& btnG=Google Search (submit) \& btnI=I\*(Aqm Feeling Lucky (submit) \& gbv=1 (hidden readonly) .Ve .ie n .SS "$mech\->dump_text( [$fh] )" .el .SS "\f(CW$mech\fP\->dump_text( [$fh] )" .IX Subsection "$mech->dump_text( [$fh] )" Prints a dump of the text on the current page to \fI\f(CI$fh\fI\fR. If \fI\f(CI$fh\fI\fR is not specified or is undef, it dumps to \s-1STDOUT.\s0 .SH "OVERRIDDEN LWP::UserAgent METHODS" .IX Header "OVERRIDDEN LWP::UserAgent METHODS" .ie n .SS "$mech\->\fIclone()\fP" .el .SS "\f(CW$mech\fP\->\fIclone()\fP" .IX Subsection "$mech->clone()" Clone the mech object. The clone will be using the same cookie jar as the original mech. .ie n .SS "$mech\->\fIredirect_ok()\fP" .el .SS "\f(CW$mech\fP\->\fIredirect_ok()\fP" .IX Subsection "$mech->redirect_ok()" An overloaded version of \f(CW\*(C`redirect_ok()\*(C'\fR in LWP::UserAgent. This method is used to determine whether a redirection in the request should be followed. .PP Note that WWW::Mechanize's constructor pushes \s-1POST\s0 on to the agent's \&\f(CW\*(C`requests_redirectable\*(C'\fR list. .ie n .SS "$mech\->request( $request [, $arg [, $size]])" .el .SS "\f(CW$mech\fP\->request( \f(CW$request\fP [, \f(CW$arg\fP [, \f(CW$size\fP]])" .IX Subsection "$mech->request( $request [, $arg [, $size]])" Overloaded version of \f(CW\*(C`request()\*(C'\fR in LWP::UserAgent. Performs the actual request. Normally, if you're using WWW::Mechanize, it's because you don't want to deal with this level of stuff anyway. .PP Note that \f(CW$request\fR will be modified. .PP Returns an HTTP::Response object. .ie n .SS "$mech\->update_html( $html )" .el .SS "\f(CW$mech\fP\->update_html( \f(CW$html\fP )" .IX Subsection "$mech->update_html( $html )" Allows you to replace the \s-1HTML\s0 that the mech has found. Updates the forms and links parse-trees that the mech uses internally. .PP Say you have a page that you know has malformed output, and you want to update it so the links come out correctly: .PP .Vb 3 \& my $html = $mech\->content; \& $html =~ s[</option>.{0,3}</td>][</option></select></td>]isg; \& $mech\->update_html( $html ); .Ve .PP This method is also used internally by the mech itself to update its own \s-1HTML\s0 content when loading a page. This means that if you would like to \fIsystematically\fR perform the above \s-1HTML\s0 substitution, you would overload \fIupdate_html\fR in a subclass thusly: .PP .Vb 2 \& package MyMech; \& use base \*(AqWWW::Mechanize\*(Aq; \& \& sub update_html { \& my ($self, $html) = @_; \& $html =~ s[</option>.{0,3}</td>][</option></select></td>]isg; \& $self\->WWW::Mechanize::update_html( $html ); \& } .Ve .PP If you do this, then the mech will use the tidied-up \s-1HTML\s0 instead of the original both when parsing for its own needs, and for returning to you through \f(CW\*(C`content()\*(C'\fR. .PP Overloading this method is also the recommended way of implementing extra validation steps (e.g. link checkers) for every \s-1HTML\s0 page received. \*(L"warn\*(R" and \*(L"die\*(R" would then come in handy to signal validation errors. .ie n .SS "$mech\->credentials( $username, $password )" .el .SS "\f(CW$mech\fP\->credentials( \f(CW$username\fP, \f(CW$password\fP )" .IX Subsection "$mech->credentials( $username, $password )" Provide credentials to be used for \s-1HTTP\s0 Basic authentication for all sites and realms until further notice. .PP The four argument form described in LWP::UserAgent is still supported. .ie n .SS "$mech\->get_basic_credentials( $realm, $uri, $isproxy )" .el .SS "\f(CW$mech\fP\->get_basic_credentials( \f(CW$realm\fP, \f(CW$uri\fP, \f(CW$isproxy\fP )" .IX Subsection "$mech->get_basic_credentials( $realm, $uri, $isproxy )" Returns the credentials for the realm and \s-1URI.\s0 .ie n .SS "$mech\->\fIclear_credentials()\fP" .el .SS "\f(CW$mech\fP\->\fIclear_credentials()\fP" .IX Subsection "$mech->clear_credentials()" Remove any credentials set up with \f(CW\*(C`credentials()\*(C'\fR. .SH "INHERITED UNCHANGED LWP::UserAgent METHODS" .IX Header "INHERITED UNCHANGED LWP::UserAgent METHODS" As a subclass of LWP::UserAgent, WWW::Mechanize inherits all of LWP::UserAgent's methods. Many of which are overridden or extended. The following methods are inherited unchanged. View the LWP::UserAgent documentation for their implementation descriptions. .PP This is not meant to be an inclusive list. \s-1LWP::UA\s0 may have added others. .ie n .SS "$mech\->\fIhead()\fP" .el .SS "\f(CW$mech\fP\->\fIhead()\fP" .IX Subsection "$mech->head()" Inherited from LWP::UserAgent. .ie n .SS "$mech\->\fImirror()\fP" .el .SS "\f(CW$mech\fP\->\fImirror()\fP" .IX Subsection "$mech->mirror()" Inherited from LWP::UserAgent. .ie n .SS "$mech\->\fIsimple_request()\fP" .el .SS "\f(CW$mech\fP\->\fIsimple_request()\fP" .IX Subsection "$mech->simple_request()" Inherited from LWP::UserAgent. .ie n .SS "$mech\->\fIis_protocol_supported()\fP" .el .SS "\f(CW$mech\fP\->\fIis_protocol_supported()\fP" .IX Subsection "$mech->is_protocol_supported()" Inherited from LWP::UserAgent. .ie n .SS "$mech\->\fIprepare_request()\fP" .el .SS "\f(CW$mech\fP\->\fIprepare_request()\fP" .IX Subsection "$mech->prepare_request()" Inherited from LWP::UserAgent. .ie n .SS "$mech\->\fIprogress()\fP" .el .SS "\f(CW$mech\fP\->\fIprogress()\fP" .IX Subsection "$mech->progress()" Inherited from LWP::UserAgent. .SH "INTERNAL-ONLY METHODS" .IX Header "INTERNAL-ONLY METHODS" These methods are only used internally. You probably don't need to know about them. .ie n .SS "$mech\->_update_page($request, $response)" .el .SS "\f(CW$mech\fP\->_update_page($request, \f(CW$response\fP)" .IX Subsection "$mech->_update_page($request, $response)" Updates all internal variables in \f(CW$mech\fR as if \f(CW$request\fR was just performed, and returns \f(CW$response\fR. The page stack is \fBnot\fR altered by this method, it is up to caller (e.g. \&\f(CW\*(C`request\*(C'\fR) to do that. .ie n .SS "$mech\->_modify_request( $req )" .el .SS "\f(CW$mech\fP\->_modify_request( \f(CW$req\fP )" .IX Subsection "$mech->_modify_request( $req )" Modifies a HTTP::Request before the request is sent out, for both \s-1GET\s0 and \s-1POST\s0 requests. .PP We add a \f(CW\*(C`Referer\*(C'\fR header, as well as header to note that we can accept gzip encoded content, if Compress::Zlib is installed. .ie n .SS "$mech\->\fI_make_request()\fP" .el .SS "\f(CW$mech\fP\->\fI_make_request()\fP" .IX Subsection "$mech->_make_request()" Convenience method to make it easier for subclasses like WWW::Mechanize::Cached to intercept the request. .ie n .SS "$mech\->\fI_reset_page()\fP" .el .SS "\f(CW$mech\fP\->\fI_reset_page()\fP" .IX Subsection "$mech->_reset_page()" Resets the internal fields that track page parsed stuff. .ie n .SS "$mech\->\fI_extract_links()\fP" .el .SS "\f(CW$mech\fP\->\fI_extract_links()\fP" .IX Subsection "$mech->_extract_links()" Extracts links from the content of a webpage, and populates the \f(CW\*(C`{links}\*(C'\fR property with WWW::Mechanize::Link objects. .ie n .SS "$mech\->\fI_push_page_stack()\fP" .el .SS "\f(CW$mech\fP\->\fI_push_page_stack()\fP" .IX Subsection "$mech->_push_page_stack()" The agent keeps a stack of visited pages, which it can pop when it needs to go \s-1BACK\s0 and so on. .PP The current page needs to be pushed onto the stack before we get a new page, and the stack needs to be popped when \s-1BACK\s0 occurs. .PP Neither of these take any arguments, they just operate on the \f(CW$mech\fR object. .ie n .SS "warn( @messages )" .el .SS "warn( \f(CW@messages\fP )" .IX Subsection "warn( @messages )" Centralized warning method, for diagnostics and non-fatal problems. Defaults to calling \f(CW\*(C`CORE::warn\*(C'\fR, but may be overridden by setting \&\f(CW\*(C`onwarn\*(C'\fR in the constructor. .ie n .SS "die( @messages )" .el .SS "die( \f(CW@messages\fP )" .IX Subsection "die( @messages )" Centralized error method. Defaults to calling \f(CW\*(C`CORE::die\*(C'\fR, but may be overridden by setting \f(CW\*(C`onerror\*(C'\fR in the constructor. .SH "BEST PRACTICES" .IX Header "BEST PRACTICES" The default settings can get you up and running quickly, but there are settings you can change in order to make your life easier. .IP "autocheck" 4 .IX Item "autocheck" \&\f(CW\*(C`autocheck\*(C'\fR can save you the overhead of checking status codes for success. You may outgrow it as your needs get more sophisticated, but it's a safe option to start with. .Sp .Vb 1 \& my $agent = WWW::Mechanize\->new( autocheck => 1 ); .Ve .IP "cookie_jar" 4 .IX Item "cookie_jar" You are encouraged to install Mozilla::PublicSuffix and use HTTP::CookieJar::LWP as your cookie jar. HTTP::CookieJar::LWP provides a better security model matching that of current Web browsers when Mozilla::PublicSuffix is installed. .Sp .Vb 1 \& use HTTP::CookieJar::LWP (); \& \& my $jar = HTTP::CookieJar::LWP\->new; \& my $agent = WWW::Mechanize\->new( cookie_jar => $jar ); .Ve .IP "protocols_allowed" 4 .IX Item "protocols_allowed" This option is inherited directly from LWP::UserAgent. It allows you to whitelist the protocols you're willing to allow. .Sp .Vb 3 \& my $agent = WWW::Mechanize\->new( \& protocols_allowed => [ \*(Aqhttp\*(Aq, \*(Aqhttps\*(Aq ] \& ); .Ve .Sp This will prevent you from inadvertently following URLs like \&\f(CW\*(C`file:///etc/passwd\*(C'\fR .IP "protocols_forbidden" 4 .IX Item "protocols_forbidden" This option is also inherited directly from LWP::UserAgent. It allows you to blacklist the protocols you're unwilling to allow. .Sp .Vb 3 \& my $agent = WWW::Mechanize\->new( \& protocols_forbidden => [ \*(Aqfile\*(Aq, \*(Aqmailto\*(Aq, \*(Aqssh\*(Aq, ] \& ); .Ve .Sp This will prevent you from inadvertently following URLs like \&\f(CW\*(C`file:///etc/passwd\*(C'\fR .IP "strict_forms" 4 .IX Item "strict_forms" Consider turning on the \f(CW\*(C`strict_forms\*(C'\fR option when you create a new Mech. This will perform a helpful sanity check on form fields every time you are submitting a form, which can save you a lot of debugging time. .Sp .Vb 1 \& my $agent = WWW::Mechanize\->new( strict_forms => 1 ); .Ve .Sp If you do not want to have this option globally, you can still turn it on for individual forms. .Sp .Vb 1 \& $agent\->submit_form( fields => { foo => \*(Aqbar\*(Aq } , strict_forms => 1 ); .Ve .SH "WWW::MECHANIZE'S GIT REPOSITORY" .IX Header "WWW::MECHANIZE'S GIT REPOSITORY" WWW::Mechanize is hosted at GitHub. .PP Repository: <https://github.com/libwww\-perl/WWW\-Mechanize>. Bugs: <https://github.com/libwww\-perl/WWW\-Mechanize/issues>. .SH "OTHER DOCUMENTATION" .IX Header "OTHER DOCUMENTATION" .SS "\fISpidering Hacks\fP, by Kevin Hemenway and Tara Calishain" .IX Subsection "Spidering Hacks, by Kevin Hemenway and Tara Calishain" \&\fISpidering Hacks\fR from O'Reilly (<http://www.oreilly.com/catalog/spiderhks/>) is a great book for anyone wanting to know more about screen-scraping and spidering. .PP There are six hacks that use Mech or a Mech derivative: .IP "#21 WWW::Mechanize 101" 4 .IX Item "#21 WWW::Mechanize 101" .PD 0 .IP "#22 Scraping with WWW::Mechanize" 4 .IX Item "#22 Scraping with WWW::Mechanize" .IP "#36 Downloading Images from Webshots" 4 .IX Item "#36 Downloading Images from Webshots" .IP "#44 Archiving Yahoo! Groups Messages with WWW::Yahoo::Groups" 4 .IX Item "#44 Archiving Yahoo! Groups Messages with WWW::Yahoo::Groups" .IP "#64 Super Author Searching" 4 .IX Item "#64 Super Author Searching" .IP "#73 Scraping \s-1TV\s0 Listings" 4 .IX Item "#73 Scraping TV Listings" .PD .PP The book was also positively reviewed on Slashdot: <http://books.slashdot.org/article.pl?sid=03/12/11/2126256> .SH "ONLINE RESOURCES AND SUPPORT" .IX Header "ONLINE RESOURCES AND SUPPORT" .IP "\(bu" 4 WWW::Mechanize mailing list .Sp The Mech mailing list is at <http://groups.google.com/group/www\-mechanize\-users> and is specific to Mechanize, unlike the \s-1LWP\s0 mailing list below. Although it is a users list, all development discussion takes place here, too. .IP "\(bu" 4 \&\s-1LWP\s0 mailing list .Sp The \s-1LWP\s0 mailing list is at <http://lists.perl.org/showlist.cgi?name=libwww>, and is more user-oriented and well-populated than the WWW::Mechanize list. .IP "\(bu" 4 Perlmonks .Sp <http://perlmonks.org> is an excellent community of support, and many questions about Mech have already been answered there. .IP "\(bu" 4 WWW::Mechanize::Examples .Sp A random array of examples submitted by users, included with the Mechanize distribution. .SH "ARTICLES ABOUT WWW::MECHANIZE" .IX Header "ARTICLES ABOUT WWW::MECHANIZE" .IP "\(bu" 4 <http://www.ibm.com/developerworks/linux/library/wa\-perlsecure/> .Sp \&\s-1IBM\s0 article \*(L"Secure Web site access with Perl\*(R" .IP "\(bu" 4 <http://www.oreilly.com/catalog/googlehks2/chapter/hack84.pdf> .Sp Leland Johnson's hack #84 in \fIGoogle Hacks, 2nd Edition\fR is an example of a production script that uses WWW::Mechanize and HTML::TableContentParser. It takes in keywords and returns the estimated price of these keywords on Google's AdWords program. .IP "\(bu" 4 <http://www.perl.com/pub/a/2004/06/04/recorder.html> .Sp Linda Julien writes about using HTTP::Recorder to create WWW::Mechanize scripts. .IP "\(bu" 4 <http://www.developer.com/lang/other/article.php/3454041> .Sp Jason Gilmore's article on using WWW::Mechanize for scraping sales information from Amazon and eBay. .IP "\(bu" 4 <http://www.perl.com/pub/a/2003/01/22/mechanize.html> .Sp Chris Ball's article about using WWW::Mechanize for scraping \s-1TV\s0 listings. .IP "\(bu" 4 <http://www.stonehenge.com/merlyn/LinuxMag/col47.html> .Sp Randal Schwartz's article on scraping Yahoo News for images. It's already out of date: He manually walks the list of links hunting for matches, which wouldn't have been necessary if the \&\f(CW\*(C`find_link()\*(C'\fR method existed at press time. .IP "\(bu" 4 <http://www.perladvent.org/2002/16th/> .Sp WWW::Mechanize on the Perl Advent Calendar, by Mark Fowler. .IP "\(bu" 4 <http://www.linux\-magazin.de/ausgaben/2004/03/datenruessel/> .Sp Michael Schilli's article on Mech and WWW::Mechanize::Shell for the German magazine \fILinux Magazin\fR. .SS "Other modules that use Mechanize" .IX Subsection "Other modules that use Mechanize" Here are modules that use or subclass Mechanize. Let me know of any others: .IP "\(bu" 4 Finance::Bank::LloydsTSB .IP "\(bu" 4 HTTP::Recorder .Sp Acts as a proxy for web interaction, and then generates WWW::Mechanize scripts. .IP "\(bu" 4 Win32::IE::Mechanize .Sp Just like Mech, but using Microsoft Internet Explorer to do the work. .IP "\(bu" 4 WWW::Bugzilla .IP "\(bu" 4 WWW::CheckSite .IP "\(bu" 4 WWW::Google::Groups .IP "\(bu" 4 WWW::Hotmail .IP "\(bu" 4 WWW::Mechanize::Cached .IP "\(bu" 4 WWW::Mechanize::Cached::GZip .IP "\(bu" 4 WWW::Mechanize::FormFiller .IP "\(bu" 4 WWW::Mechanize::Shell .IP "\(bu" 4 WWW::Mechanize::Sleepy .IP "\(bu" 4 WWW::Mechanize::SpamCop .IP "\(bu" 4 WWW::Mechanize::Timed .IP "\(bu" 4 WWW::SourceForge .IP "\(bu" 4 WWW::Yahoo::Groups .IP "\(bu" 4 WWW::Scripter .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to the numerous people who have helped out on WWW::Mechanize in one way or another, including Kirrily Robert for the original \f(CW\*(C`WWW::Automate\*(C'\fR, Lyle Hopkins, Damien Clark, Ansgar Burchardt, Gisle Aas, Jeremy Ary, Hilary Holz, Rafael Kitover, Norbert Buchmuller, Dave Page, David Sainty, H.Merijn Brand, Matt Lawrence, Michael Schwern, Adriano Ferreira, Miyagawa, Peteris Krumins, Rafael Kitover, David Steinbrunner, Kevin Falcone, Mike O'Regan, Mark Stosberg, Uri Guttman, Peter Scott, Philippe Bruhat, Ian Langworth, John Beppu, Gavin Estey, Jim Brandt, Ask Bjoern Hansen, Greg Davies, Ed Silva, Mark-Jason Dominus, Autrijus Tang, Mark Fowler, Stuart Children, Max Maischein, Meng Wong, Prakash Kailasa, Abigail, Jan Pazdziora, Dominique Quatravaux, Scott Lanning, Rob Casey, Leland Johnson, Joshua Gatcomb, Julien Beasley, Abe Timmerman, Peter Stevens, Pete Krawczyk, Tad McClellan, and the late great Iain Truskett. .SH "AUTHOR" .IX Header "AUTHOR" Andy Lester <andy at petdance.com> .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2004\-2016 by Andy Lester. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Génération de la page: 0.01 |
proxy
|
phpinfo
|
Réglages