2013-11-20 3 views
2


웹 페이지의 항목 콘텐츠 부서 내에서 정보를 얻으려고하고 있습니다. 내 스크립트가 기다리고 새 항목을 읽으 려합니다. 웹 페이지에 나타나는 콘텐츠 구분. 어떤 제안?WWW :: Mechanize :: Firefox를 사용하여 게시물이 나타날 때까지 기다리십시오.

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

페이지를 가져온 후에는 새로운 콘텐츠를 얻는 유일한 방법은 다시 자바 스크립트를 가져 오는 것입니다 (자바 스크립트가 없다고 가정). 'Last-Modified' 헤더가 변경 될 때까지 페이지를 폴링 할 수 있지만 먼저 사이트의 사용 조건을 확인해야합니다. – ThisSuitIsBlackNot

답변

0

매우 간단한 구현입니다. 이 작업을 사용하기 전에 @ThisSuitIsBlack을 따르지 말고이 작업을 수행했는지 확인하십시오.

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;