LWP Post

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to figure out how use LWP::UserAgent to get dynamically
generated Web pages using the POST method. I've followed the examples
in the O'Reilly book: Perl & LWP by Sean M. Burke. There's an example
there of posting to the AltaVista Babelfish translator, and this
example works fine for me. But when I try to do someting similar on
another page, it fails.

For example, I tried to get morphological analysis (word structure
analysis) from http://www.uni-plovdiv.bg/dcs/morphe.htm , and even
though it's a very simple minded form, I had no success. Sean Burke
has a program in his book called formpairs, which allows you to test
what posted info a form is expecting. I used this and checked very
carefully, but still, no success.

Here's what the form looks like:

function FrontPage_Form1_Validator(theForm)

  if (theForm.D1.selectedIndex < 0)
    alert("Please select one of the \"D1\" options.");
    return (false);
  return (true);
//--></script><!--webbot BOT="GeneratedScript" endspan --><form
action="http://rdesc.pu.acad.bg/cgi-bin/cgi_morf.exe " method="POST"
onsubmit="return FrontPage_Form1_Validator(this)"
  <p><textarea name="S1" rows="5" cols="82"></textarea></p>
  <p><!--webbot bot="Validation" b-value-required="TRUE" --><select
name="D1" size="3">
    <option>1.Windows ( )</option>
    <option>2.Macintosh ( abvgde'zijklmnoprstufxchw]=;_q )</option>
    <option>3.QWERTY ( abwgdevzijklmnoprstufhc`[]yx\q )</option>

  <p><input type="submit" name="B1" value="Analysis"></p>

You see that there's a bit of Javascript getting in the way, but I
don't think thats a problem here. [You also see that the author of the
page mixed up is terminology and referred to ASCII as QWERTY.
But that's beside the point.] I tried to access this page with the

use strict;
use LWP;
my $browser;
sub do_POST {
  # Parameters:
  #  the URL,
  #  an arrayref or hashref for the key/value pairs,
  #  and then, optionally, any header lines: (key,value, key,value)
  $browser = LWP::UserAgent->new(  ) unless $browser;
  my $resp = $browser->post(@_);
  return ($resp->content, $resp->status_line, $resp->is_success, $resp)
    if wantarray;
  return unless $resp->is_success;
  return $resp->content;

my ($content, $message, $is_success) = do_POST(
  'http://www.uni-plovdiv.bg/dcs/morphe.htm ',
  [ 'S1' => 'ne', 'B1' => "Analysis",
    'D1'=>'3.QWERTY ( abwgdevzijklmnoprstufhc`[]yx\q )' ],

print "$content\n";

Anybody have any ideas???

Dale Gerdemann

Re: LWP Post

dg@sfs.nphil.uni-tuebingen.de (Dale Gerdemann) writes:

> my ($content, $message, $is_success) = do_POST(
>   'http://www.uni-plovdiv.bg/dcs/morphe.htm ',
>   [ 'S1' => 'ne', 'B1' => "Analysis",
>     'D1'=>'3.QWERTY ( abwgdevzijklmnoprstufhc`[]yx\q )' ],
> );
> print "$content\n";
> Anybody have any ideas???

You don't want to post to the HTML page with the form on it, you want
to post to their program. Try something like

  my ($content, $message, $is_success) = do_POST(
    'http://rdesc.pu.acad.bg/cgi-bin/cgi_morf.exe ',
    [ 'S1' => 'ne',
      'D1' => '3.QWERTY ( abwgdevzijklmnoprstufhc`[]yx\q )',
      'B1' => "Analysis",

instead (note the different URL). When I do that, I get

  <BODY bgcolor="#FFFFFF">
  <P>ne :Particle,  :189 1 base form:ne</P>

I hope this helps,


Site Timeline