use strict;
use warnings;
use WWW::Mechanize;
use HTML::TreeBuilder;
use utf8;
use Encode;
binmode STDOUT, ':utf8';
sub say {print @_, "\n";}
open(IN, '<:encoding(utf8)', 'word_list.txt');
open(OUT, ">word_list_output.txt");
while(<IN>){
chomp;
my ($word) = split(/,/, $_);
my $mech = WWW::Mechanize->new();
$mech->agent_alias( 'Windows IE 6' );
$mech->get('http://eow.alc.co.jp/serch');
print $word."\n\n";
$mech->submit_form(
fields => {
q => "$word",
}
) or die 'submitting failed';
my $res = $mech->content;
my $tree = HTML::TreeBuilder->new;
$tree->parse($res);
$tree->look_down('class', 'wordclass');
my @items =$tree->find('tag', 'ol');
my $input_wd = encode('utf8',$items[0]->as_text);
print OUT $word."\t";
print OUT $input_wd."\n";
$tree->delete;
};
close(IN);
close(OUT);