我想将所有名称都转储到this page上,并保留所有剩余的146页。

红色/橙色的上一个/下一个按钮将使用JavaScript进行接缝,并通过AJAX获取名称。



是否可以编写脚本来爬行146页并转储名称?

是否存在用于这种事情的Perl模块?

最佳答案

您可以为此使用WWW::Mechanize或其他Crawler。 Web::Scraper可能也是一个好主意。

use Web::Scraper;
use URI;
use Data::Dump;

# First, create your scraper block
my $scraper = scraper {
    # grab the text nodes from all elements with class type_firstname (that way you could also classify them by type)
    process ".type_firstname", "list[]" => 'TEXT';
};

my @names;
foreach my $page ( 1 .. 146) {
  # Fetch the page (add page number param)
  my $res = $scraper->scrape( URI->new("http://www.familiestyrelsen.dk/samliv/navne/soeginavnelister/godkendtefornavne/drengenavne/?tx_lfnamelists_pi2[gotopage]=" . $page) );
  # add them to our list of names
  push @names, $_ for @{ $res->{list} };
}

dd \@names;


它会为您列出所有名称的很长的清单。运行它可能需要一些时间。首先尝试使用1..1

09-27 03:44