i run a tiny little script with perl Mechanize :: Firefox
- Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my @urls = qw(
http://www.google.com
http://www.yahoo.com
http://www.cnn.com
http://www.bing.com
http://www.nbcnews.com
);
my $temp = '/tmp';
my $mech = WWW::Mechanize::Firefox->new('create');
foreach my $url (@urls){
my ($name) = $url =~ /www\.(\w+)\.com/;
print "creating $name.png\n";
$mech->get($url);
sleep(5);
my $png = $mech->content_as_png(undef, undef, {width => 240, height => 240});
my $file = "$temp/$name".".png";
open my $fh, ">", $file or die "couldnt create $file";
binmode $fh;
print $fh $png;
close $fh;
}
print "done\n";
Well if i run this above mentioned code it gives the following output in the termina
- Code: Select all
l
martin@linux-70ce:~> cd perl
martin@linux-70ce:~/perl> ls
mech1.pl mech2 mech2.pl mech3.pl
martin@linux-70ce:~/perl> perl mech3.pl
creating google.png
creating yahoo.png
creating cnn.png
creating bing.png
creating nbcnews.png
done
martin@linux-70ce:~/perl> ^C
martin@linux-70ce:~/perl>
well the above mentioned code will write the results to the /tmp directory, at the root level of the drive.
If we reboot, they'll be gone, but it's a place any process can write to regardless of user. That is the good thing.
We have to do some changes:
Well we have to do a change with the the directory to whatever location we want.
well i try to get the files created in a folder in /perl