2012-11-02 15:14:13 +01:00
|
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
|
|
#use strict;
|
|
|
|
|
#use warnings;
|
|
|
|
|
use Web::Scraper;
|
|
|
|
|
use URI;
|
|
|
|
|
use HTML::Entities;
|
|
|
|
|
use Encode;
|
|
|
|
|
use URI::Escape;
|
|
|
|
|
use LWP::UserAgent;
|
2014-09-21 01:56:45 +02:00
|
|
|
|
use utf8;
|
2012-11-02 15:14:13 +01:00
|
|
|
|
|
|
|
|
|
my $type = $ARGV[0];
|
|
|
|
|
if ($type !~ /^\./)
|
|
|
|
|
{
|
|
|
|
|
$type = ".$type";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $scrap = scraper {
|
|
|
|
|
process '//table/tr/td', 'table[]' => 'TEXT';
|
|
|
|
|
};
|
|
|
|
|
my $url = URI->new("http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains");
|
|
|
|
|
my $res = $scrap->scrape($url);
|
|
|
|
|
my $table = $res->{'table'};
|
2012-11-09 20:04:06 +01:00
|
|
|
|
my $found = 0;
|
2014-09-21 01:56:45 +02:00
|
|
|
|
for ($i = 0; $i < $#$table && found != 1; $i++)
|
2012-11-02 15:14:13 +01:00
|
|
|
|
{
|
|
|
|
|
if ($$table[$i] =~ /^\.[^ ]*$/ && $$table[$i+1] !~ /^No$/ && $$table[$i+1] !~ /^Yes$/ && $$table[$i+1] !~ /^Partial\[/ && $$table[$i+1] !~ /^$/)
|
|
|
|
|
{
|
|
|
|
|
#print "$$table[$i] is $$table[$i+1]\n";
|
|
|
|
|
if ($$table[$i] =~ /^$type$/)
|
|
|
|
|
{
|
2014-09-21 01:56:45 +02:00
|
|
|
|
($result = $$table[$i+1]) =~ s/^ //;
|
|
|
|
|
print "$type is ";
|
|
|
|
|
binmode(STDOUT, ":utf8");
|
|
|
|
|
print "$result\n";
|
2012-11-09 20:04:06 +01:00
|
|
|
|
$found = 1;
|
2012-11-02 15:14:13 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$i++;
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
if ($$table[$i] =~ /^xn--/)
|
|
|
|
|
{
|
2014-09-21 01:56:45 +02:00
|
|
|
|
$tabletype_enc = encode("utf8", $$table[$i+1]);
|
2012-11-02 15:14:13 +01:00
|
|
|
|
#print "$$table[$i+1] is $$table[$i+2]\n";
|
2015-10-12 12:49:33 +02:00
|
|
|
|
if ($tabletype_enc =~ /^$type$/)
|
2012-11-02 15:14:13 +01:00
|
|
|
|
{
|
2014-09-21 01:56:45 +02:00
|
|
|
|
($result = $$table[$i+2]) =~ s/^ //;
|
|
|
|
|
print "$type is ";
|
|
|
|
|
binmode(STDOUT, ":utf8");
|
|
|
|
|
print "$result\n";
|
2012-11-09 20:04:06 +01:00
|
|
|
|
$found = 1;
|
2012-11-02 15:14:13 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$i+=5;
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-09 20:04:06 +01:00
|
|
|
|
if ($found == 0)
|
|
|
|
|
{
|
|
|
|
|
print "$type is unknown\n";
|
|
|
|
|
}
|