WWW::Me...ookbook(3)
π¦ WWW::Mechanize::Cookbook(3) π¦
π User Contributed Perl Documentation π
okay bestie, this is the recipe collection for WWW::Mechanize, and we are gonna make it make sense. no cap. β¨
πΈ NAME πΈ
WWW::Mechanize::Cookbook β Recipes for using WWW::Mechanize
π VERSION π
version 2.19
β¨ INTRODUCTION β¨
okay so first things first, bestie: a bunch of these recipes 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. π«Ά
π BASICS π
π Launch the WWW::Mechanize browser
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. π
π Fetch a page
$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.
π Fetch a page into a file
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" );
π§ Fetch a password-protected page
Generally, just call credentials before fetching the page.
$mech->credentials( 'admin' => 'password' );
$mech->get( 'http://10.11.12.13/password.html' );
print $mech->content();
π LINKS π
πΌοΈ Find all image links
Find all links that point to a JPEG, GIF or PNG.
my @links = $mech->find_all_links(
tag => "a", url_regex => qr/\.(jpe?g|gif|png)$/i );
β¬οΈ Find all download links
Find all links that have the word "download" in them.
my @links = $mech->find_all_links(
tag => "a", text_regex => qr/\bdownload\b/i );
π₯ ADVANCED π₯
π See what will be sent without actually sending anything
$mech->add_handler("request_send", sub { shift->dump; exit; });
$mech->get("http://www.example.com");
π SEE ALSO π
WWW::Mechanize
π AUTHOR π
Andy Lester β <andy at petdance.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2004 by Andy Lester.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
That's the whole recipe book, bestie. This page is from perl v5.42.0, dated 2024-09-17, and the footer is literally WWW::Me...ookbook(3) β stay slaying those HTTP requests π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-WWW-Mechanize 2.190.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms