好吧,对我来说,Perl 有时看起来很像 Abracadabra,非常感谢您对我的耐心...
更新; joe 让我发布不起作用的完整脚本:这里我们有我在暴民回答后尝试过的代码(见下文)
一直出现严重错误:
martin@linux-wyee:~/perl> perl test_8.pl
syntax error at test_8.pl line 25, near ")
binmode"
Global symbol "$out" requires explicit package name at test_8.pl line 25.
Global symbol "$out" requires explicit package name at test_8.pl line 26.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl> su -
这是我当前运行的脚本...
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = new WWW::Mechanize::Firefox();
open my $urls, '<', 'urls.txt' or die $!;
while (<$urls>) {
chomp;
next unless /^http/i;
print "$_\n";
$mech->get($_);
my $png = $mech->content_as_png;
my $name = $_;
$name =~ s#^http://##i;
$name =~ s#/##g;
$name =~ s/\s+\z//;
$name =~ s/\A\s+//;
$name =~ s/^www\.//;
$name .= ".png";
open(my $out, '>', "/images/$name")
binmode $out;
print $out $png;
close $out;
sleep 5;
}
这里有五个示例网址......
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
更新结束;在这里原始的初始线程继续......
我需要一些来自网站的缩略图,但我尝试使用 wget - 但这对我不起作用,因为我需要一些渲染功能需要什么:我有一个包含 2,500 个 URL 的列表,每行一个,保存在一个文件中. 然后我想要一个脚本 - 见下文 - 打开文件,读取一行,然后检索网站并将图像保存为小缩略图。好吧,因为我有一堆网站(2500),所以我必须对结果的命名下定决心。
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
到目前为止一切顺利,我想我尝试这样的事情
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = new WWW::Mechanize::Firefox();
open my $urls, '<', 'urls.txt' or die $!;
while (<$urls>) {
chomp;
next unless /^http/i;
print "$_\n";
$mech->get($_);
my $png = $mech->content_as_png;
my $name = $_;
$name =~ s#^http://##i;
$name =~ s#/##g;
$name =~ s/\s+\z//;
$name =~ s/\A\s+//;
$name =~ s/^www\.//;
$name .= ".png";
open my $out, ">", $ "images" or die $!;
binmode $out;
print $out $png;
close $out;
sleep 5;
}
运行一个小脚本并收集/获取结果......我将图像收集为缩略图。到目前为止,一切都很好。
注意:到目前为止一切都很好并且运行良好,直到 - 是的,直到我尝试创建一个特殊选项:我想强制脚本将结果存储在一个文件夹中
好吧,您如何看待将结果存储在一个名为 images 左右的文件夹中的想法!?)这可行吗?这会很有帮助,因为我将结果存储在一个文件夹中。而且很多结果都不会弄乱机器...
我遇到了一些问题。试图做到这一点 - 因此将其存储在一个目录中:
open(my $out, '>', "path/$name") or die $!;
我是这样做的。。
注意 -名为 images 的目录位于同一个文件夹中......
我得到结果
perl test_8.pl
Global symbol "$images" requires explicit package name at test_8.pl line 23.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl>
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$/images"
(Missing operator before images?)
syntax error at test_8.pl line 23, near "$/images "
Global symbol "$out" requires explicit package name at test_8.pl line 24.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$/images"
(Missing operator before images?)
syntax error at test_8.pl line 23, near "$/images "
Global symbol "$out" requires explicit package name at test_8.pl line 24.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl>
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$ "images"
(Missing operator before images?)
String found where operator expected at test_8.pl line 23, at end of line
(Missing semicolon on previous line?)
syntax error at test_8.pl line 23, near "$ "images"
Can't find string terminator '"' anywhere before EOF at test_8.pl line 23.
martin@linux-wyee:~/perl>