| Category: | web robots |
| Author/Contact Info | Claudio Garcia claudio.garcia@stanfordalumni.org |
| Description: | This is a simple web client that will bring a word
definition from the UCSD web dictionary into your X
terminal. If people are interested I also have a server-simpler client version that allows this program to be deployed on a large number of machines without having to install the LWP and HTML packages it uses on each of them.
|
#!/usr/bin/perl -w
use HTML::TreeBuilder;
use HTML::FormatText;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->agent("Dictionary");
#
# Uncomment if behind a firewall
#
#$ua->proxy([ 'http' ], 'http://www-dms.esd.sgi.com:8080/');
#
# Create a new request.
#
my $req = new HTTP::Request GET => "http://work.ucsd.edu:5141/cgi-bin/
+http_webster?isindex=$ARGV[0]&method=exact";
#
# Pass Request to the user agent and get a response back.
#
my $res = $ua->request($req);
#
# Print outcome of the response.
#
if(! $res->is_success) {
print "Failure to connect to server: " . $res->message;
} else {
my $html = $res->content;
my $p = HTML::TreeBuilder->new;
$p->parse($html);
my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin =
+> 60);
my $result = $formatter->format($p);
my @paragraphs = split /^\s+/m, $result;
#
# Print only the paragraphs where the word definition is
#
for(my $x=2; !($paragraphs[$x] =~ /^From WordNet/) and $x < 10; $x++
+) {
print $paragraphs[$x]."\n";
}
}
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: webster client
by Anonymous Monk on May 17, 2000 at 10:59 UTC | |
by gregorovius (Friar) on May 17, 2000 at 19:25 UTC | |
by Anonymous Monk on May 18, 2000 at 18:53 UTC | |
by Melvin (Beadle) on May 22, 2000 at 15:37 UTC | |
by gregorovius (Friar) on May 22, 2000 at 21:14 UTC |