2012-03-31 63 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

相關問題