new-words
view lingvo-en-ru.pl @ 51:74e05d4436ee
minifix: spanish + italian
author | Igor Chubin <igor@chub.in> |
---|---|
date | Sun May 01 20:25:55 2011 +0200 (2011-05-01) |
parents | |
children |
line source
1 #!/usr/bin/perl
3 # written by Andrii Grytsenko, 2010
5 use Locale::Recode;
6 use LWP::UserAgent;
7 use strict;
10 sub parse_html {
11 my $text = shift;
12 my $result ;
13 $text =~ s/></>\n</g;
14 foreach my $line (split(/\n/,$text)){
15 $result .= $line."\n" if ( $line =~ /span class=.translation/ or $line =~ /lol-dict-name/ or
16 $line =~ /span class=.Abbrev./ or $line =~ /span class=.comment./);
17 }
18 return $result;
19 }
21 sub print_html {
22 my $text = shift;
23 my $class = 0;
24 foreach my $line (split(/\n/,$text)){
25 $line =~ s/<[^>]+>//g ; #delete all html tags
26 print "$line\n";
27 }
28 }
31 my $cd = Locale::Recode->new (from => 'UTF-8', to => 'koi8-r');
32 die $cd->getError if $cd->getError;
33 my $ua = LWP::UserAgent->new;
34 $ua->agent("Firefox/0.1 ");
36 my $word = $ARGV[0];
37 my $req = HTTP::Request->new(GET => "http://lingvo.abbyyonline.com/en/en-ru/$word");
39 my $res = $ua->request($req);
41 if ($res->is_success) {
42 my $text = $res->content;
43 $cd->recode($text); # change code encoding from UTF-8 to koi8-ru
44 print "Translate for word $word\n";
45 $text = parse_html($text);
46 print_html($text);
47 } else {
48 print $res->status_line, "\n";
49 }