sadarax has asked for the wisdom of the Perl Monks concerning the following question:
A simple program to take a screencapture of a webpage in a web-browser (in this case Firefox).
#!/usr/bin/perl -w use warnings; use strict; use WWW::Mechanize::Firefox; my $url = "http://cmcc.deviantart.com"; my $outfile = "MyScreenshot.png"; my $telnet_max_buff_len = 10485760; my $mech = WWW::Mechanize::Firefox->new( launch => 'firefox',); my $net_telnet = $mech->repl->repl->client; # Bridge deep into WWW:Tel +net for finer control $net_telnet->telnet->max_buffer_length($telnet_max_buff_len); # Enable + buffer size to handle large webpage $mech->get($url); # Grab the content my $png = $mech->content_as_png(); # Dump to a PNG file open my $out, '>', $outfile or die "Couldn't create '$outfile': $!"; binmode $out; # Enable binary mode print {$out} $png; # Write the file to disk
You will need to have WWW::Mechanize::Firefox installed (which can be done through cpan), and you will need to have the firefox addon MozRepl installed (http://wiki.github.com/bard/mozrepl). Module::Pluggable::Fast is, for some reason, not installable through the CPAN shell. You will need to download it separately and extract and install it manually by doing the following dance:
1. Download Module::Pluggable::Fast
2. Extract the tarball somewhere convenient
3. Open a shell in that directory
4. Type cpan . (including that dot)
5. Watch the module get installed
6. Retry installing WWW::Mechanize::Firefox
This should work. Thanks everyone again.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Screencapture with Perl on Linux
by Corion (Patriarch) on Dec 05, 2009 at 14:26 UTC | |
by LanX (Saint) on Dec 05, 2009 at 16:06 UTC | |
by Corion (Patriarch) on Dec 05, 2009 at 16:12 UTC | |
by LanX (Saint) on Dec 05, 2009 at 16:19 UTC | |
by Corion (Patriarch) on Dec 05, 2009 at 16:33 UTC | |
by sadarax (Sexton) on Dec 06, 2009 at 00:48 UTC | |
by Corion (Patriarch) on Dec 06, 2009 at 08:35 UTC | |
| |
|
Re: Screencapture with Perl on Linux
by Khen1950fx (Canon) on Dec 05, 2009 at 13:36 UTC | |
by sadarax (Sexton) on Dec 06, 2009 at 00:20 UTC | |
|
Re: Screencapture with Perl on Linux
by LanX (Saint) on Dec 05, 2009 at 13:44 UTC | |
|
Re: Screencapture with Perl on Linux
by stefbv (Priest) on Dec 05, 2009 at 13:28 UTC | |
|
Re: Screencapture with Perl on Linux
by LanX (Saint) on Dec 06, 2009 at 22:42 UTC |