logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

WWW::Mechanize::Cookbook - Recipes for using WWW::Mechanize

Advanced

Seewhatwillbesentwithoutactuallysendinganything
           $mech->add_handler("request_send", sub { shift->dump; exit; });
           $mech->get("http://www.example.com");

Author

       Andy Lester <andy at petdance.com>

Basics

LaunchtheWWW::Mechanizebrowser
           use WWW::Mechanize;

           my $mech = WWW::Mechanize->new( autocheck => 1 );

       The "autocheck => 1" tells Mechanize to die if any IO fails, so you don't have to manually check.  It's
       easier that way.  If you want to do your own error checking, leave it out.

   Fetchapage
           $mech->get( "http://search.cpan.org" );
           print $mech->content;

       "$mech->content" contains the raw HTML from the web page.  It is not parsed or handled in any way, at
       least through the "content" method.

   Fetchapageintoafile
       Sometimes you want to dump your results directly into a file.  For example, there's no reason to read a
       JPEG into memory if you're only going to write it out immediately.  This can also help with memory issues
       on large files.

           $mech->get( "http://www.cpan.org/src/stable.tar.gz",
                       ":content_file" => "stable.tar.gz" );

   Fetchapassword-protectedpage
       Generally, just call "credentials" before fetching the page.

           $mech->credentials( 'admin' => 'password' );
           $mech->get( 'http://10.11.12.13/password.html' );
           print $mech->content();

Introduction

       First, please note that many of these are possible just using LWP::UserAgent.  Since "WWW::Mechanize" is
       a subclass of LWP::UserAgent, whatever works on "LWP::UserAgent" should work on "WWW::Mechanize".  See
       the lwpcook man page included with LWP.

Name

       WWW::Mechanize::Cookbook - Recipes for using WWW::Mechanize

See Also

       WWW::Mechanize

Version

       version 2.19

See Also