我喜欢perl,只是学习我没有使用Web::Scraper
模块的工作。它使用CSS
选择器来提取表中的列和由第二个,其指示dependencias每个包的数目将它们排序:
的script.pl
文件:
#!/usr/bin/env perl
use strict;
use warnings;
use Web::Scraper;
use URI;
die qq|Usage: perl $0 <url>\n| unless @ARGV == 1;
my $packages_deps = scraper {
process 'tr', 'package_deps[]' => scraper {
process 'td:first-child > a', 'package_name' => 'TEXT';
process 'td:nth-child(2)', 'tot_deps' => 'TEXT';
};
result 'package_deps';
};
my $response = $packages_deps->scrape(URI->new(shift));
for (sort { $a->{tot_deps} <=> $b->{tot_deps} } @$response[1..$#$response]) {
printf qq|%d %s\n|, $_->{tot_deps}, $_->{package_name};
}
运行它提供的网址:
perl script.pl "http://packdeps.haskellers.com/reverse"
和取得(只显示列表的开头和结尾部分):
1 abstract-par-accelerate
1 accelerate-fft
1 acme-year
1 action-permutations
1 active
1 activehs-base
...
766 text
794 filepath
796 transformers
915 directory
1467 mtl
1741 bytestring
1857 containers
5287 base