drake50 has asked for the wisdom of the Perl Monks concerning the following question:

I would like to have my perl program click the agree button automatically and then load the next page into memory but I haven't been able to figure it out. The website is http://www.bluffsdogs.com/recent_results.asp. Is it possible to use something like the following:
#!/usr/bin/perl -w # this is untested use strict; use WWW::Mechanize; my $url = 'http://www.bluffsdogs.com/recent_results.asp'; my $robot = new WWW::Mechanize; $robot->get($url); $robot->form_number('0'); $robot->set_fields('radiobutton' => 'true'); $robot->click(); # Get the reply to my question my $html = $robot->content(); print "$html";

Replies are listed 'Best First'.
Re: form posting question
by Corion (Patriarch) on May 19, 2004 at 20:40 UTC

    Why do you ask whether it is possible?

    Does the program work? Where does it fail?

    If you don't tell us what the problem with your script is, we can't help you. If you didn't write the script yourself, maybe tell us what the script is supposed to do and where it fails for you or where your problem with the script is.

      It doesn't work.

      I don't know what to put for the form_number and I don't know what to use for the set_fields.

      I don't know how to make any headway on this because it isn't defined as a normal form.
      mech-dump --forms http://www.bluffsdogs.com/recent_results.asp
      <input> outside <form> at /usr/lib/perl5/site_perl/5.8.0/WWW/Mechanize.pm line 1335
      <input> outside <form> at /usr/lib/perl5/site_perl/5.8.0/WWW/Mechanize.pm line 1335
      

        In such cases, ugly as it is, it helps to look at the HTML on the page:

        ... <td> <input name="radiobutton" type="radio" onMouseUp="MM_goToURL('parent','agree.asp'); return document.MM_returnValue" value="radiobutton"> I agree </td> <td> <input name="radiobutton" type="radio" onMouseUp="MM_goToURL('parent','recent_resultsdisagree.asp'); return document.MM_returnValue" value="radiobutton"> I disagree </td>

        So, the site uses Javascript, instead of an HTML form to store the result. WWW::Mechanize does not do JavaScript, so you'll have to help it out. Most likely, the MM_goToUrl('parent', 'agree.asp') call moves you to the /agree.asp page. So you could simply try to directly use:

        $agent->get('http://www.bluffsdogs.com/agree.asp');

        or try that line after you've retrieved the user agreement page. WWW::Mechanize tries to make stuff easy, but some times, you still have to look at the HTML for the cause of the problems...