我想转储this page上的所有名字以及所有剩余的 146 页。
红色/橙色的上一个/下一个按钮使用 JavaScript 缝合,并通过 AJAX 获取名称。
问题
是否可以编写一个脚本来抓取 146 个页面并转储名称?
是否存在用于此类事情的 Perl 模块?
最佳答案
您可以使用WWW::Mechanize或另一个爬虫。 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
。
关于javascript - 可以从网页转储 AJAX 内容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552753/