单击div标签

时间:2012-11-05 19:34:56

标签: perl web-scraping

我正在使用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

1 个答案:

答案 0 :(得分:2)

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