Well to me Perl sometimes looks abit Abracadabra
i need to have some thumbnails from websites: i tried to use wget - but that does not work for me, since i need some rendering functions
but i tried to use wget - but that does not work for me, since i need some rendering functions
what is needet: i have a list of 2,500 URLs, one on each line, saved in a file. Then i want a script - see it below - to open the file, read a line, then retrieve the website and save the image as a small thumbnail.
well since i have a bunch of web-sites (2500) i have to make up my mind about the naming of the results.
http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
http://www.phtg.ch
http://www.phsg.ch
http://www.phsh.ch
http://www.phr.ch
http://www.hepfr.ch/
http://www.phbern.ch
So far so good, well i think i try something like this
We also have to close a filehandler if we do not need it anymore.,
Besides this we can use 'or die' on open.
Btw we need a good file name. Since i have a huge list of urls then i get a huge list of output files.
Therefore i need to have good file names. Can we reflect those things and needs in the programme!?
the script does not start at all ....
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = new WWW::Mechanize::Firefox();
open(INPUT, "<urls.txt") or die $!;
while (<INPUT>) {
chomp;
next if $_ =~ m/http/i;
print "$_\n";
$mech->get($_);
my $png = $mech->content_as_png();
my $name = "$_";
$name =~s#http://##is;
$name =~s#/##gis;$name =~s#\s+\z##is;$name =~s#\A\s+##is;
$name =~s/^www\.//;
$name .= ".png";
open(my $out, ">",$name) or die $!;
binmode($out);
print $out $png;
close($out);
sleep (5);
}
well - i think that some thing is not correct with the regex and the sanitizing....
any guess - sometimes it looks abracadava
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.