【问题标题】:Wait for a post to appear using WWW::Mechanize::Firefox使用 WWW::Mechanize::Firefox 等待帖子出现
【发布时间】:2013-11-20 15:39:03
【问题描述】:


我试图在网页的项目内容部门中获取信息,我希望我的脚本等待并阅读网页中出现的任何新项目内容部门。有什么建议吗?

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;

【问题讨论】:

  • 获取页面后,获取新内容的唯一方法是再次获取它(假设没有 JavaScript 在起作用)。您可以轮询页面,直到 Last-Modified 标头更改,但您应该先查看网站的使用条款。

标签: perl screen-scraping www-mechanize-firefox


【解决方案1】:

这是一个非常简单的实现。在使用它之前,请遵循@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;

【讨论】:

    猜你喜欢
    • 2014-04-14
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多