2013-11-20 86 views
2


我試圖獲取網頁的項目內容部門內的信息,我希望我的腳本等待並閱讀任何新的項目 - 內容部門出現在網頁上。有什麼建議麼?等待帖子出現使用WWW ::機械化::火狐

use WWW::Mechanize::Firefox; 

my $mech = WWW::Mechanize::Firefox->new(); 
$mech->get('https://openbook.etoro.com/Dellos/overview/'); 
my @text = $mech->selector('.item-content'); 

for my $p (0..$#text) { 
    my $normal=$text[$p]->{innerHTML}; 
    print $normal; 
} 
exit; 
+1

一旦你獲取了頁面,獲得新內容的唯一方法就是再次獲取它(假設沒有JavaScript在播放)。您可以輪詢該頁面直到「Last-Modified」標題更改,但您應該首先檢查網站的使用條款。 – ThisSuitIsBlackNot

回答

0

這是一個非常簡單的實現。在使用此之前,請按照@ThisSuitIsBlackNot建議來確保它可以做到這一點。

use WWW::Mechanize::Firefox; 

my $mech = WWW::Mechanize::Firefox->new(); 
my %seen; 
while (1){ 
    $mech->get('https://openbook.etoro.com/Dellos/overview/'); 
    my @text = $mech->selector('.item-content'); 
    for my $p (0..$#text) { 
    next if $seen{$p}; 
    my $normal=$text[$p]->{innerHTML}; 
    print $normal; 
    $seen{$p} = 1; 
    } 
    sleep 30; 
} 
exit;