#! /usr/bin/perl -w

use strict;
use warnings;
use utf8;

use LWP::Simple;
binmode STDOUT => 'encoding(utf8)';

my $file = shift @ARGV || exit;
my $list;

open $list, "<$file" || exit;

my ($url, $content);
while ($url = <$list>) {
    sleep 1;
    chomp $url;
    print STDERR "getting $url : ";
    $content = get($url);
    if (! $content) {
        print STDERR "NG\n";
        print "$url -> <NG>\n";
        next;
    }
    print STDERR "OK\n";
    if ($content =~ /<title>([^<]+)<\/title>/) {
        my $title = $1;
        print "$url -> $title\n";
    }
    else {
        print "$url -> <?>\n";
    }
}
