我创建了以下 perl 脚本来从 Web 中提取 URL:
#!perl
use strict;
use warnings;
use List::MoreUtils qw( uniq );
use WWW::Mechanize qw( );
my ($url) = @ARGV;
my $mech = WWW::Mechanize->new();
sub getUrl {
my $request= "@_";
my $response = $mech->get($request);
return $response->is_success() or die($response->status_line() . "\n");
}
sub getLinks {
getUrl($url);
my @root= map { "$_\n" } sort { $a cmp $b } uniq
map { $_->url_abs() }
$mech->links();
return @root;
}
print Dumper(getLinks());
是否有解决方案如何从 HTML 站点中提取唯一 URL 和相关链接文本?