0

我正在使用 WWW::Scripter 来抓取一个用 javascript/ajax 编写的页面,到下一页的“链接”是一个 div 标签,我可以获取该标签,但似乎无法找到一种方法来单击它以获取下一页..有什么建议吗?

my $w = new WWW::Scripter;
$w->use_plugin('Ajax'); 
$w->get($c->website);

my $loop = 1;
my $page = 1;

while ($loop) {
  my $te = HTML::TableExtract->new();
  $content = $w->content();

  $te->parse($content);
  $table = $te->first_table_found;
  $str .= Dumper $table;
  $page += 1;

  $loop = $self->next_page($w);
}

sub next_page {
my $self = shift;
my $w = shift;
$div = $w->document->getElementById('example_next');
if (defined $div) {
--I want to click on the div and move to the next page, suggestions?---
return 1;
} else {
return 0;
}
}

示例 html 代码...首先有一个表格保存数据...

 <table class="display" id="example">
<thead>
    headers
</thead>
<tbody>---DATA---</tbody>
 </table>

然后分页从“页面”到“页面”,每次分页点击都会重写数据。

<div class="dataTables_paginate paging_two_button" id="example_paginate">
<div class="paginate_disabled_previous" title="Previous" id="example_previous"></div>
<div class="paginate_enabled_next" title="Next" id="example_next"></div>
</div>

这都是使用 www.datatables.net

4

1 回答 1

2

您需要识别单击该 div 的 id 时发生的 JavaScript 调用,然后执行它。或者,您可以使用 WWW::Mechanize::Firefox 或 WWW::Selenium。

于 2012-11-05T22:20:23.153 回答