Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks  

Re: Re: form posting question

by drake50 (Pilgrim)
on May 19, 2004 at 17:01 UTC ( [id://354762]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: form posting question
in thread form posting question

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

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

    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...

      Using the url agree.asp worked. Thanks!

      Just out of curiosity how would you normally deal with javascript?
        Send the "webmaster" a nasty email?

        --Bob Niederman, http://bob-n.com

        All code given here is UNTESTED unless otherwise stated.

      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???

        Does the $agent->links method, as found in the WWW::Mechanize documentation not work for you?

        my @links = grep {$_->text /$pattern/i} $agent->links(); for (@links) { storeurl( $_->url, $trackname, $year ); };

        I suggest that you read the WWW::Mechanize documentation, as it contains many helpfull hints about what is possible with WWW::Mechanize.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://354762]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.