I have need of writing a perl program to interact with an html form that includes radio buttons. Unfortunately, I do not have control over the form, and those who wrote it forgot to close the form with a "/form" tag within their html code. (So the form is started with the proper "form" tag, but is never ended with the "/form" tag.)

Following the code in the HTTP::Request::Form documentation, I tried doing something like this:


use URI::URL;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common qw(POST);
use HTTP::Request::Form;
use HTML::TreeBuilder 3.0;
use Data::Dumper;

my $ua = LWP::UserAgent->new();
my $url = 'http://formhost/form.cgi';
my $req = $ua->request(GET $url);
my $tree = HTML::TreeBuilder->new();
$tree->parse($req->content);
$tree->eof();

my @forms = $tree->find_by_tag_name('form');
die "No forms found in $url\n" unless @forms;
print Dumper @forms;
exit 0;


This code always dies because nothing shows up in the @forms array due (I think) to the fact that find_by_tag_name('form') is unable to find the closing tag.

How can I interact with the radio buttons? Can I just use POST in HTTP::Request::Common in some way? Or, is there some other function within HTML::TreeBuilder that I can use?

Thanks,

--Mike

In reply to LWP and improper by mbr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.