看到更新在intail发布
- 以及我有点confued结束我不得不承认... ;-)是一个新手Perl的朋友的Perl代码荃看起来有点abracadaba ....
我需要从网站上一些缩略图,但我试图使用wget - 但是这对我不起作用,因为我需要一些渲染函数needet:我有一个2500个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/$name");
binmode $out;
print $out $png;
close $out;
sleep 5;
}
我现在得到下面的结果.... 看到什么出来...... 和远正如我所见 - 没有图像存储在文件夹“图像”
为什么不!
[email protected]:~> cd perl
[email protected]:~/perl> perl test_8.pl
http://www.unifr.ch/sfm
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 2.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 2.
http://www.zug.phz.ch
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 3.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 3.
http://www.schwyz.phz.ch
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 4.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 4.
http://www.luzern.phz.ch
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 5.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 5.
http://www.schwyz.phz.ch
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 6.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 6.
http://www.phvs.ch
binmode() on closed filehandle $out at test_8.pl line 25, <$urls> line 14.
print() on closed filehandle $out at test_8.pl line 26, <$urls> line 14. http://www.pfh-gr.ch Got status code 500 at test_8.pl line 15 [email protected]:~/perl>
什么是输出要告诉我... 现在我该怎么办!?
更新
你好我亲爱的
THX的答复 - 猜,我这里有一个权限问题....
以及我有这个...
#!/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")or die $!;
binmode $out;
print $out $png;
close $out;
sleep 5;
}
那么这个工程 - 但我可以得到的是存储到test_8.pl所在的目录
猜测这是一个权限问题。
我能做些什么。
我可以把图片目录放在perl文件夹的外面..? 也许我创建了
perl-directory或 images-directory有一些特殊的根权限。
我做了什么来解决这些问题至今是
A- checkint上的文件夹 的权限 - perl的 。 perl/images
b.-以root用户身份在命令行中运行脚本。
好allll我可以得到的是存储在文件夹中的结果,...
linux-wyee:/home/martin/perl_dev/perl # ls
.directory images module_test pfh-gr.ch.png phsg.ch.png phtg.ch.png schwyz.phz.ch.png test_4.pl test_8.pl urls.txt
heilpaedagogik.phbern.ch.png luzern.phz.ch.png module_test.pl phbern.ch.png phsh.ch.png phvs.ch.png test_2.pl test_6.pl test_8.pl~ zug.phz.ch.png
hepfr.ch.png ma-shp.luzern.phz.ch.png open-local-file.pl phr.ch.png ph-solothurn.ch.png .png test_3.pl test_7.pl unifr.chsfm.png
linux-wyee:/home/martin/perl_dev/perl #
图像文件夹为空
我能做些什么
高度重视和我创建图像Perl的目录
如何命名字符串路径把它外面文件夹内。 ?!
亲爱的伙伴 - 我们重新的allmost那里 - 我很肯定 - 我想,这仅仅是一个权限问题。但如何解决它!?
也许我要再次创造了一个全新的目录中的所有testfiles。不是作为root用户而是正常用户!?你说什么!?
语句'open(my $ out,'>',“/ images/$ name”)似乎是失败的添加'或者死亡$!'来排除故障。 – Melioratus 2012-03-31 01:07:45
[perl-mechanize遇到限制的几个可能的重复 - 几次调试尝试开始](http://stackoverflow.com/questions/9656892/perl-mechanize-runs-into-limitations-several-debugging-attempts-started) – 2012-03-31 01:13:51
hello .-看到更新的inital发布 - 猜你是正确的 – zero 2012-03-31 11:19:23