Randy Mullis said...
>
>
>
>I hope someone can help with this question.  I would like to retrieve the
>results of submitting a form.  I have used LWP:simple a little to do this
>and it has worked like a charm with input boxes, radio buttons, and check
>boxes.  I am stumped, however, by the need to select from a list in order to
>retrieve results.  An abbreviated example would be:
>
>    <select name="S1" size="10" col="35">
>        <option value="andrew_cook">andrew_cook</option>
>        <option value="andrew_cook_mod">andrew_cook_mod</option>
>        <option value="barbara_smith">barbara_smith</option>
>        <option value="barbara_smith_mod">barbara_smith_mod</option>
>    </select></TD>
>
>I tried making my request look like:
>
>       my $req = POST 'http://www.foo.com/cgi/server?action=24&c=203',
>                     S1 => "$username_mod",
>                     B2 => 'Submit' ];
>

Get the document that contains the form.
Parse the returned content with HTML::Form.
Extract the form you want to 'fill out'.
Set the values of the named elements of the form.
Then submit the form to the URL listed in the 'action' attribute of the
form tag.

my $res = $ua->request($req);
my @forms = HTML::Form->parse($res->content,$base);
my $form = grep { $_->action =~ /server/ } @forms;
$form->value('action', 24);
$form->value('c',203);
$form->value('S1',$username_mod);
$form->value('B2','Submit'); # might not need this
$req = $form->click;

$newRes = $ua->request($req);

And oh yes don't forget error checking...:)


-- 
Tim Allwine
IX Development Laboratories

Reply via email to