in reply to Re: Getting result page using WWW::Mechanize
in thread Getting result page using WWW::Mechanize

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

Replies are listed 'Best First'.
Re: Re: Re: Getting result page using WWW::Mechanize
by Corion (Patriarch) on Jul 04, 2003 at 10:31 UTC

    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.

        As long as you don't post the URL of the site you are trying to automate, I can only poke around in the dark - an exercise not very rewarding. I suggest that you install my module WWW::Mechanize::Shell, which allows you to explore a website interactively and afterwards spit out a complete Perl script that recreates what you did manually.

        My guess is, that the following commands in WWW::Mechanize::Shell should be sufficient in getting you to your goal :

        get http://www.example.com/ value login "username" value password "secret" click "Login" # You get a page back which is a frame page links # look at the links open "/data_frame/" value age 99 click "continue" content

        If you absolutely do not get WWW::Mechanize::Shell to install, I will try to translate that script into Perl manually, but please try ::Shell first, as it can display the current page in your browser for easy review.

        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