我喜歡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