in reply to Getting result page using WWW::Mechanize

Actually, you are getting two things here :

The message There is no form numbered 1 at /usr/pweb/phonekerala/cgi-bin/thisis.pl line 26 is a warning caused by the code :

$agent->form_number('1');

WWW::Mechanize::Shell adds this code as a safety measure in case the first form is not automatically selected.

The most likely reason why you get that warning though is, that the first call to get did not return a valid page, this is why you can't set the values in the second try. Check this by adding a line like

print "Got the page ", $agent->content;
or
die $agent->res->as_string unless $agent->content;

I will implement a die_on_http_failure for WWW::Mechanize in one of the upcoming releases that will make the whole script die horribly if any http request fails - but don't hold your breath for that :-)

Mostly, this will implement the following idiom :

die $agent->res->as_string unless $agent->res->is_success;
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Getting result page using WWW::Mechanize
by Anonymous Monk on Jul 04, 2003 at 10:10 UTC

    Hi Corion,

    Thanks for your help and . I made some changes like this and working fine... but still not getting the

    #!/usr/bin/perl print "Content-type: text/html\n\n"; use warnings; use strict; use WWW::Mechanize; use CGI; my $cgi = CGI->new(); my $form = $cgi->Vars; my $agent = WWW::Mechanize->new(); $agent->get('http:/mydomain.com/html/yes.html'); $agent->form_number('0'); ##changes made here $agent->form_name('test'); ## Added $form->{UserId}='test01'; $form->{Passwd} = 's'; $agent->field('UserId',$form->{UserId}); $agent->field('Passwd',$form->{Passwd}); $agent->submit(); ##$agent->get('http://mydomain.com/cg-bin/login.cgi?#UserId='.$for +m-> #+{UserId}.'&Passwd='.$form->{Passwd}); print $agent->content();

    Submitting this form will call a html that contains frame... in that frame set, one frame is calling a cgi .. it's ponting to the location where i am running the script... That's why i am geting error as "Page can't be found.

    I think u are the author of "WWW::Mechanize::Shell " module. Just now i go through that module... Excellent. So could you please tell me how to handle multiple files using your module... In my result page , i have a text field and submit button... so how can i input the parameter and submit that form?

    Please send me the valuable solution and suggestion to tackle these type of problems...

    Once again thanks for your help.
    Regards
    ps

    20030704 Edit by Corion: Fixed formatting

      If you have to navigate a page containing frames, you have to navigate first to the frame page, and then use

      $agent->follow();

      to get to the page linked from that frame.

      To set the value of a text field, use $agent->field("fieldname",$value);. To submit a form with a single button, you can either use $agent->submit() or $agent->click("button_name")

      BTW, take a look at the Writeup Formatting Tips to see how to format code and your text.

      perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
        Hi Corion, Thank you for helping me to write the basic steps to implement the module. Still i didn't get any idea if i go for second level of form (First level is to get the inputs and submit and it will display a page. The second level is, in the display page if i have a text field say "age" and two buttons "continue" and "stop". I would like to input in the text field and click on the continue button . How can i add these steps in my previous code? It will be very useful for me, if you post that part. Thanks a lot.