blob: 5fdbe68e7b1f3bb10d04505b8a17a730fb9d813c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/perl
#use strict;
#use warnings;
use Web::Scraper;
use URI;
use HTML::Entities;
use Encode;
use URI::Escape;
use LWP::UserAgent;
use utf8;
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'};
my $found = 0;
for ($i = 0; $i < $#$table && found != 1; $i++)
{
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$/)
{
($result = $$table[$i+1]) =~ s/^ //;
print "$type is ";
binmode(STDOUT, ":utf8");
print "$result\n";
$found = 1;
break;
}
$i++;
next;
}
if ($$table[$i] =~ /^xn--/)
{
$tabletype_enc = encode("utf8", $$table[$i+1]);
#print "$$table[$i+1] is $$table[$i+2]\n";
if ($tabletype_enc =~ /$type/)
{
($result = $$table[$i+2]) =~ s/^ //;
print "$type is ";
binmode(STDOUT, ":utf8");
print "$result\n";
$found = 1;
break;
}
$i+=5;
next;
}
}
if ($found == 0)
{
print "$type is unknown\n";
}
|