Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

webster client

by gregorovius (Friar)
on May 04, 2000 at 17:07 UTC ( #10239=sourcecode: print w/replies, xml ) Need Help??
Category: web robots
Author/Contact Info Claudio Garcia
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.
Usage: % webster_client word
#!/usr/bin/perl -w

use HTML::TreeBuilder;
use HTML::FormatText;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;

# Uncomment if behind a firewall
#$ua->proxy([ 'http' ], '');

# Create a new request.
my $req = new HTTP::Request GET => "

# 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;
  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 06:59 UTC
    This looks great! One question though, would it be possible to modify this for a foreign language dictonary? I'd love to be able to type check dog and have it give me from an online german dictonary der Hund, -e
      Sure! I have a Spanish-English version already. If you point me to an on-line english-german dictionary I'll make it work with it.(or you may do it yourself and post the new version back)
        A german-english dictionary is avaible at
        This is the german dictionary I prefer. Providing as much information on the word as possible would be the most useful, such as article, the plural form, etc etc. I'll take a look at it myself and post my results, but I'd love to see your spanish port.
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://10239]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2019-12-14 12:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found