in reply to form posting question

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.

Replies are listed 'Best First'.
Re: Re: form posting question
by drake50 (Pilgrim) on May 19, 2004 at 21:01 UTC
    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...

        The following code worked...
        #!/usr/bin/perl -w # this code worked use strict; use WWW::Mechanize; my $url = 'http://www.bluffsdogs.com/agree.asp'; my $robot = new WWW::Mechanize; $robot->get($url); #$robot->form_number(''); #$robot->form_name(''); #$robot->set_fields('radiobutton' => 'true'); #$robot->click(); # Get the reply to my question my $html = $robot->content(); print "$html";
        ...BUT...

        Now I want to be able to parse the results for links. In another program I used something like:
        my $response = $browser->get($baseurl,@ns_headers); die "$baseurl error: ", $response->status_line unless $response->is_success; die "Weird content type at $baseurl -- ", $response->content_type unless $response->content_type eq 'text/html'; my $html = $response->content; # save all files that match pattern given - ignore case while( $html =~ m/<a.{1,40}href=(.*?)>/ig ) { my $matchline = $1; #print "matchline = $matchline\n"; if($matchline =~ m/\"(.*?)\"/ig ) { $matchline=$1; $sawcount++; } # else keep what you have $savestr= URI->new_abs( $matchline, $response->base ); #print "savestr = $savestr\n"; if ($savestr =~ /$pattern/i ) {$savecount++;&storeurl($savestr,$ +trackname,$year)}; } print "I saw $sawcount URLs and thought $savecount where of intere +st.\n";
        Is it possible use things like $savestr= URI->new_abs( $matchline, $response->base ); with Mechanize???
        Using the url agree.asp worked. Thanks!

        Just out of curiosity how would you normally deal with javascript?