2012-03-31 60 views
-1

看到更新在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用户而是正常用户!?你说什么!?

+2

语句'open(my $ out,'>',“/ images/$ name”)似乎是失败的添加'或者死亡$!'来排除故障。 – Melioratus 2012-03-31 01:07:45

+0

[perl-mechanize遇到限制的几个可能的重复 - 几次调试尝试开始](http://stackoverflow.com/questions/9656892/perl-mechanize-runs-into-limitations-several-debugging-attempts-started) – 2012-03-31 01:13:51

+0

hello .-看到更新的inital发布 - 猜你是正确的 – zero 2012-03-31 11:19:23

回答

5

您无法打开文件写。你的路径是/图像,你可能没有对目录的权限(如果存在的话)。总是检查您的电话返回值为open,就像您在第一个open中所做的那样。

如果我是你,我不会用/图像。我会将所有内容下载到我控制的目录中,而不是混淆标准目录布局。如果您没有进行系统管理,则几乎不应在/下创建新目录。

+0

你好,亲爱的布莱恩·d FOY法力感谢 - 以及OU是对的 - 我检查的权限 - 我希望以后一切顺利。 thx再次为你所做的一切。许多许多问候 - – zero 2012-03-31 01:55:50

+0

**更新**以及我改变了权限,并再次尝试它 - 它仍然失败......注意:有一个版本的脚本是文件werent写在一个额外的文件夹 - 运行良好。 **为什么?** – zero 2012-03-31 02:03:22

+0

你好大脑你好所有 - 在初始发布看到更新...我想你是对的 – zero 2012-03-31 11:19:03

相关问题