Esteemed Monks,

I am trying to scrape a site using WWW::Mechanize. Somehow, I am not managing to submit a very simply form containing radio buttons. I hope you can help! This is the form code from the page source:
<form method="post" action="http://..."> <div class="ABC"> <div class="DEF"><input type="radio" name="Radio" id="1" value="1" />< +label for="1">Option1</label></div> <div class="DEF"><input type="radio" name="Radio" id="2" value="2" />< +label for="2">Option2</label></div> <div class="DEF"><input type="radio" name="Radio" id="3" value="3" />< +label for="3">Option3</label></div> </div> <div class="buttons"> <div class="spacer"></div> <input type="submit" class="form_buttons" name="submit" value="Submit +Form" /> <div class="form_buttons"><a href="http://..." title="...">...</a></di +v> <input type="hidden" name="ID" value="Form_ID" /> <div class="spacer"></div> </div> </form>

And this is how I tried to submit the form:
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use Crypt::SSLeay; use HTTP::Cookies; my $agent = WWW::Mechanize->new(); my $cookie_file = "Cookies.txt"; $agent -> cookie_jar( HTTP::Cookies->new( File => $cookie_file, autosa +ve => 1 )); my $page = 'http://...'; # Request the page. $agent -> get( $page ); # Set the radiobutton 'Radio' to the second option. $agent -> set_fields( 'Radio' => '2' ); # Now post the poll form to the URL given in the source code under act +ion="http://...". $agent -> post( 'http://...' );

Thanks for your help with this in advance!
Cheers -
Pat

In reply to Problem submitting form with Mechanize by pat_mc

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.