WWW::Me...xamples(3)
π WWW::Me...xamples(3) β the one where the examples get their own manpage π
okay bestie, so this is a page from the User Contributed Perl Documentation collection, and it's literally just the vibes tour of the example programs that ship inside the WWW::Mechanize::Chrome distribution. No code to run here, it's docs only. Come look at the little guys. π¦
π NAME
Examples β WWW::Mechanize::Chrome example programs. that's it, that's the name, slay.
β¨ DESCRIPTION
okay so this is a documentation-only module, meaning it doesn't do anything, it just shows off the example programs that are included in the WWW::Mechanize::Chrome distribution. think of it as the little gallery wall of the codebase. πΌοΈ
also not me, but this whole file was auto-generated via the gen_examples_pod.pl program β which is also included in the examples directory. so the examples generated the page about the examples. iconic recursive behavior tbh. π₯
π Example programs
so here's the full lineup: 5 example programs are included in the WWW::Mechanize::Chrome distribution. not four. not six. five. periodt.
Example: url-to-image.plβ take a screenshot of a website πΈExample: html-to-pdf.plβ convert HTML to PDF πExample: dump-links.plβ dump links on a webpage πExample: sendkeys.plβ send keystrokes to a page β¨οΈExample: javascript.plβ execute Javascript in the webpage context β‘
πΈ Example: url-to-image.pl
the plot: screenshot a website, save it as a PNG. here's the whole thing, verbatim, no notes:
#!/usr/bin/perl
use strict;
use File::Spec;
use File::Basename 'dirname';
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
my $mech = WWW::Mechanize::Chrome->new();
sub show_screen() {
my $page_png = $mech->content_as_png();
my $fn= File::Spec->rel2abs(dirname($0)) . "/screen.png";
open my $fh, '>', $fn
or die "Couldn't create '$fn': $!";
binmode $fh, ':raw';
print $fh $page_png;
close $fh;
#system(qq(start "Progress" "$fn"));
};
$mech->get('http://act.yapc.eu/gpw2017');
show_screen;
=head1 NAME
url-to-image.pl
=head1 SYNOPSIS
perl url-to-image.pl
=head1 DESCRIPTION
This example fetches a web page and creates a screenshot in PNG format
in the script's directory.
and yes, the script's own embedded POD says it too: this example fetches a web page and creates a screenshot in PNG format, in the script's directory. π
Download this example: https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/url-to-image.pl
π¦ Example: html-to-pdf.pl
this one takes a URL and turns it into a PDF. look at the code:
#!perl -w
use strict;
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
my $url = shift @ARGV
or die "Usage: perl $0 <url>\n";
my $mech = WWW::Mechanize::Chrome->new(
headless => 1, # otherwise, PDF printing will not work
);
print "Loading $url";
$mech->get($url);
my $fn= 'screen.pdf';
my $page_pdf = $mech->content_as_pdf(
filename => $fn,
);
print "\nSaved $url as $fn\n";
=head1 NAME
html-to-pdf.pl
=head1 SYNOPSIS
perl html-to-pdf.pl https://www.perl.org/
=head1 DESCRIPTION
This example takes an URL from the command line, renders it and and
saves it as a PDF file in the current directory.
okay bestie important detail alert: it takes a URL from the command line, renders it, and saves it as a PDF file in the current directory. (and yes, the original comment really does say headless => 1, # otherwise, PDF printing will not work β keep it, it's load-bearing. π)
Download this example: https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/html-to-pdf.pl
π Example: dump-links.pl
reading the Chrome DOM and pulling text out of nodes. the CSS class it goes hunting for is "download". here:
#!/usr/bin/perl
use strict;
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
my $mech = WWW::Mechanize::Chrome->new();
$mech->get_local('links.html');
sleep 5;
print $_->get_attribute('href'), "\n\t-> ", $_->get_attribute('innerHTML'), "\n"
for $mech->selector('a.download');
=head1 NAME
dump-links.pl - Dump links on a webpage
=head1 SYNOPSIS
From the examples directory:
perl dump-links.pl
=head1 DESCRIPTION
This program demonstrates how to read elements out of the Chrome DOM
and how to get at text within nodes. It prints links with the CSS
class "download" from a file provided with the distribution.
=cut
so what's it doing? it demonstrates how to read elements out of the Chrome DOM and how to get at text within nodes. it prints links with the CSS class "download" from a file provided with the distribution. run it from the examples directory, like the synopsis says. π
Download this example: https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/dump-links.pl
β¨οΈ Example: sendkeys.pl
typing into a page and hitting enter. main character energy:
#!perl -w
use strict;
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($ERROR);
my $mech = WWW::Mechanize::Chrome->new();
$mech->get( 'https://google.com' );
$mech->sendkeys( string => "test\r" );
$mech->sleep( 10 );
=head1 NAME
sendkeys.pl - send keystrokes to a page
=head1 SYNOPSIS
perl sendkeys.pl
=head1 DESCRIPTION
B<This program> demonstrates how to type some input into a text field
and then press the C<enter> key.
=cut
per its own description: This program demonstrates how to type some input into a text field and then press the enter key. fr fr. π
Download this example: https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/sendkeys.pl
β‘ Example: javascript.pl
executing Javascript in the page context. note the heredoc and the lone <>; at the end β keep it exactly, that's not a typo, that's the script:
#!perl -w
use strict;
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
my $mech = WWW::Mechanize::Chrome->new();
$mech->get_local('links.html');
$mech->eval_in_page(<<'JS');
alert('Hello Frankfurt.pm');
JS
<>;
=head1 NAME
javascript.pl - execute Javascript in a page
=head1 SYNOPSIS
perl javascript.pl
=head1 DESCRIPTION
B<This program> demonstrates how to execute simple
Javascript in a page.
=cut
and per its own POD: This program demonstrates how to execute simple Javascript in a page. no cap. β¨
Download this example: https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/javascript.pl
π AUTHOR
Max Maischein "corion@cpan.org" β and heads up, the contributed examples contain the original author's name. give them their flowers too. π«Ά
π COPYRIGHT
Copyright 2009-2026 by Max Maischein "corion@cpan.org".
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
bestie this is a documentation-only module β there is nothing to call, nothing to instantiate, no options, no exit statuses, no env vars. it's just a tour of the examples. don't go looking for a new() here, it's not that kind of page. π
and that's the whole page, we ate and left no crumbs. π this little cutie is WWW::Me...xamples(3), shipped with perl v5.42.2, dated 2026-06-07 β mwah, go read the examples, ily, bye ππΈπ
π¦ where this page comes from
- fedora 43: perl-WWW-Mechanize-Chrome 0.78-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-WWW-Mechanize-Chrome 0.78-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms