2012-06-25 33 views
0

我試圖搜索但找不到密切的答案。Perl模塊(WWW :: Mechanize)從頁面選擇圖片

什麼我是這樣的(鏈接和URL將被改變,但概念將是完全一樣的)

#!/usr/bin/perl 
#Some of the modules are going to be unused for now 
use Win32::OLE; 
use Win32::Ole::Variant; 
use LWP::Simple; 
use DBI; 
use DBD::mysql; 
use WWW::Mechanize qw(); 

$url = 'http://example.com'; 
$mechanize = WWW::Mechanize->new(autocheck => 1); #BTW what's autocheck=>1 for? 
$mechanize->get($url); 
$content = $mechanize->content(); 

print $content; #Shows the HTML (OK) 

$mechanize->form_name('search'); 
$mechanize->field('level', '100'); 
$response = $mechanize->submit(); 

print $response->content(); #Shows the html of the submitted page (OK); 

現在,這種新的形式所具有的隨機圖像生成的是不是.jpg也沒有其他的圖像格式。我想要做的就是將該圖像(我知道名稱)保存到我的文件夾中。圖片標籤是<img src="someImage.php"> and I would like to save it as someImage.jpg`在一個文件夾中。

回答

2

它有助於閱讀documentation of the software you are using,你沒有這樣做。你需要圖像方法。

use strictures; 
use WWW::Mechanize qw(); 
my $m = WWW::Mechanize->new; # autocheck is default since v1.50 (year 2008) 
$m->get('file:///tmp/so11184595.html'); 
for my $i ($m->images) { 
    $m->mirror($i->url_abs, 'some/someImage.jpg') 
     if 'someImage.php' eq $i->url; 
} 
+0

我做到這一點,得到消息「無法找到對象的方法‘圖像’通過一攬子‘HTTP ::頭’,」 – Grigor

+0

該項目工程爲我寫的。你改變了它:你在'get'返回的響應對象上調用'images'方法。這是錯誤的。 – daxim

+0

如何查看圖像列表,程序是否按照您所寫的方式工作,但我看不到保存的圖像 – Grigor

相關問題