2


I´m trying to get the information within the item-contents divisions of the webpage and i would like my script to wait and read any new item-content divisions appearing in the webpage. Any suggestions?

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;
user3013745
  • 59
  • 1
  • 7
  • 1
    Once you've fetched the page, the only way to get new content would be to fetch it again (assuming there's no JavaScript at play). You could poll the page until the `Last-Modified` header changes, but you should check the site's terms of use first. – ThisSuitIsBlackNot Nov 20 '13 at 16:56

1 Answers1

0

Here is a very simple implementation. Before using this please follow @ThisSuitIsBlackNot suggestion to make sure it is Ok to do this.

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;
user1126070
  • 4,999
  • 1
  • 14
  • 14