Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take screenshots of webpages with Perl?

Tags:

perl

Is it possible to write a script in Perl that opens different URLs and saves a screenshot of each of them?

like image 598
fixxxer Avatar asked Feb 22 '10 17:02

fixxxer


People also ask

How do I screenshot a whole page inspect?

Inspect the element you wish to capture. Open the Command Menu with Cmd + Shift + P / Ctrl + Shift + P. Type in screenshot within the Command Menu. You can now capture the screenshot of only the specific element, a viewport screenshot, or a full-page screenshot.

Which tool supports taking screenshots of a webpage?

Fireshot FireShot is an extension available on the Chrome Webstore that lets you capture full web page screenshots. You may even edit and annotate captures and save them as PDF/JPEG/GIF/PNG files.


1 Answers

You could use WWW::Mechanize::Firefox to control a Firefox instance and dump the rendered page with $mech->content_as_png.

Be aware that setting it up can pose quite a challenge, though.

If all works as expected, you can simply use a script like this to dump images of the desired websites, but you should start Firefox and resize it to the desired width manually (height doesn't matter, WWW::Mechanize::Firefox always dumps the whole page).

use WWW::Mechanize::Firefox;
use Path::Class qw/file/;

my $mech = WWW::Mechanize::Firefox->new(
  bufsize => 10_000_000, # PNGs might become huge
);
$mech->get('http://www.stackoverflow.com/');

my $fh = file( 'test.png' )->open( '> :raw' );
print $fh $mech->content_as_png();
like image 166
willert Avatar answered Nov 01 '22 06:11

willert