我有一百万个网址的列表。我必须为每个 url 提取 TLD 并为每个 TLD 制作多个文件。例如收集所有带有 .com 的网址作为 tld 并将其转储到 1 个文件中,另一个申请 .edu tld 等等。在每个文件中,我必须按域名的字母顺序对其进行排序,然后按子域等进行排序。 ct 任何人都可以在 perl 中应用这个跳转吗?
我已使用 URI 模块来提取每个网址的 tld 以及域名和主机名。如何使用 com tld 收集所有网址并将它们转储到 1 个文件中?以及如何按 tld 对每个文件进行排序,然后按域然后按子域等?任何指针?
while(my $line = <$fh1>){
my $url = $line;
my @components = split(/\./, $url);
my $n_comp = ($components[-1] =~ /^edu|com|net|org|gov$/) ? 2 : 3;
my $domain = lc(join '.', @components[-$n_comp .. -1]);
$domain =~ s/^\.//; # Remove leading . if there is one.
print $fh3 $domain;
print $fh3 "\n";
my $host = URI->new($url)->host();
# Treat relative URLs as absolute URLs with missing http://.
$url = "http://$url" if $url !~ /^\w+:/;
$host =~ s/\.\z//; # D::PS doesn't handle "domain.com.".
print $fh2 $host;
print $fh2 "\n";
$dps->get_root_domain($host)
or die $dps->error();
print $fh4 $dps->tld();
print $fh4 "\n";
}