can anyone show/send me a working libwww POST ? 
Author Message
 can anyone show/send me a working libwww POST ?

forgive me if some of the following ain't too coherent, but i'm
a perl newbie (though not new to programming).

ok, i've installed perl 5.005_02 and libwww-perl 5.36 on my dec
unix 4.0 machine, and all seems ok.  i've followed the example
get() method and can successfully slurp in a URL and print out the
string or whatever, so i know my connection to the outside world
works.  i try the example POST program, but as the URL in it
has changed it doesn't work, and i can't hack some other address
to work, so, is there anybody who can send me an example of
a lump of libwww perl that POST's to a form ?  it's just so i can
try and work out how the form's value/name pairs work on the
webpage.

any advice is greatfully welcomed,

Iain.



Mon, 09 Apr 2001 03:00:00 GMT  
 can anyone show/send me a working libwww POST ?

Quote:
>forgive me if some of the following ain't too coherent, but i'm
>a perl newbie (though not new to programming).

>ok, i've installed perl 5.005_02 and libwww-perl 5.36 on my dec
>unix 4.0 machine, and all seems ok.  i've followed the example
>get() method and can successfully slurp in a URL and print out the
>string or whatever, so i know my connection to the outside world
>works.  i try the example POST program, but as the URL in it
>has changed it doesn't work, and i can't hack some other address
>to work, so, is there anybody who can send me an example of
>a lump of libwww perl that POST's to a form ?  it's just so i can
>try and work out how the form's value/name pairs work on the
>webpage.

Here's a script that will send the argument to Merriam-Webster's
on line dictionary (via a cgi post), grab & parse the definition
and finally print it.

The messiest part is the attempt at parsing the html.  I tried
HTML::Parser but couldn't make heads or tails of the documentation;
I'd be grateful if someone showed a cleaner way to implement what
follows.           -- Al

#!/usr/bin/perl -w
# Albert Danial Oct 9 1998
use strict;
use LWP::UserAgent;
use HTML::TokeParser;

my ($script, $url, $usage, $ua, $req, $result, $tempfile, $StartDef,
    $entry,

($script) = ($0 =~ /^.*?(\w+)$/);  # extract script's basename
$url      = "http://www.m-w.com/cgi-bin/dictionary";
$usage    = "
Usage:  $script  <word>
        Sends <word> to the Merriam-Webster on-line dictionary at
        http://www.m-w.com/dictionary.htm and prints the result.
";

$ua       = new LWP::UserAgent;
$req      = new HTTP::Request 'POST', $url;
$tempfile = "/tmp/temp.$script.$$";

$req->content_type('application/x-www-form-urlencoded');

$result = $ua->request($req);
open(OUT, ">$tempfile") or die "cannot write to temp.$0  $!\n";
print(OUT $result->as_string);
close(OUT);
$StartDef = 0;
my $p = HTML::TokeParser->new($tempfile) or die "Can't open $tempfile: $!";
$entry = "";
while (my $token = $p->get_token) {
    if ($token->[0] eq "T") {
        last if $token->[1] =~ /Dictionary Look Up/;
        $StartDef = 1 if $token->[1] =~ /^\nPronunciation/;
        next unless $StartDef;
        $token->[1] =~ s/&amp;/&/g;
        $token->[1] =~ s/&lt;/</g;
        $token->[1] =~ s/&gt;/>/g;
        $entry .= $token->[1];
    }

Quote:
}

unlink($tempfile);

$entry =~ s/((\D12)?\d(\s[a-z])?\s:\s)/\n$1/g;

print $entry, "\n";


    print "$_\n";

Quote:
}



Mon, 23 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. email sent via net::smtp doesn't show links

2. Anyone w/ success installing libwww on NT4.0?

3. Send mail script not working in 2nd server but working in 1st server

4. Send mail script not working in 2nd server but working in 1st server

5. libwww send var contents

6. libwww send var contents prob

7. Posting a form through libwww

8. size limits on POST requests using libwww?

9. libwww and POST

10. libwww and escaping '+' in POST

11. using libwww - problems posting to a server script...

12. libwww POST javascript

 

 
Powered by phpBB® Forum Software