于是便有了下面的脚本:
-
# 名称:在线词典
-
# 用法:$0 <word>
-
# 作者:flw
-
# 日期:2006.01.20
-
# 适用性:平台无关
-
# 依赖性:需要 HTML::TreeBuilder 模块(非标准模块,需要另行安装)
-
-
use strict;
-
use warnings;
-
use LWP;
-
use HTML::TreeBuilder;
-
-
my $word = shift || die "$0
\n" ;
-
-
my $ua = new LWP::UserAgent;
-
-
my $res = $ua->get( "" );
-
-
die $res->status_line . "\n" unless $res->is_success;
-
-
my $tree = HTML::TreeBuilder->new; # empty tree
-
my $html = $res->content;
-
$html =~ s/&.*?;//sg;
-
$html =~ s{<font color=#.+?>(.+?)</font>}{$1}sg;
-
$html =~ s{<span class=pronounce>[^<>]+</span>}{}sg;
-
$html =~ s{<object.+?</object>}{}sg;
-
$tree->parse( $html ) || return undef;
-
-
my $content = $tree->{_content}[1]->{_content}[1]->{_content}[0]->{_content}[0]->{_content}[0]->{_content}[1]->{_content}[0]->{_content}[0];
-
-
&get_content( $content );
-
-
sub get_content{
-
my $content = shift;
-
foreach my $e ( $content->content_list() ){
-
if ( ref $e ){
-
&get_content( $e );
-
}
-
else{
-
print "$e\n";
-
}
-
}
- }
-
D:\MoChou>dict
-
D:\MoChou\dict.pl <word>
-
-
D:\MoChou>dict china
-
Define
-
-
china
-
:
-
-
n. 中国,瓷器
-
-
例句与用法:
-
1.
-
China is an oriental country with a long history.
-
中国是一个有着悠久历史的东方国家。
-
2.
-
This set of ancient china is invaluable.
-
这套古瓷器非常珍贵。
-
3.
-
China is a developing country.
-
中国是一个发展中国家。
-
4.
- I
FROM: http://blog.chinaunix.net/uid-45332-id-2400709.html