Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Follow through POST method

by Agyeya (Hermit)
on May 05, 2004 at 10:05 UTC ( [id://350728]=note: print w/replies, xml ) Need Help??


in reply to Re: Follow through POST method
in thread Follow through POST method

<form name="frmChooseZone" method="post" action="ChooseZone.aspx?type= +A" id="frmChooseZone"> <input type="hidden" name="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" value="dDw0NzUyOTE0NzQ7" /> <script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform; if (window.navigator.appName.toLowerCase().indexOf("netscape") + > -1) { theform = document.forms["frmChooseZone"]; } else { theform = document.frmChooseZone; } theform.__EVENTTARGET.value = eventTarget.split("$").join(":") +; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> </script> Please Select the Consular District that covers your Residence TT Services - Web Application <table id="rdlZone" class="RBtnList" cellspacing="1" cellpadding="1" b +order="0"> <input onclick="__doPostBack('rdlZone_0','')">US Consulate Chennai (Ma +dras) <input onclick="__doPostBack('rdlZone_1','')">US Embassy New Delhi <input onclick="__doPostBack('rdlZone_2','')">US Consulate Calcutta (K +olkata)
This is the part of the relevant code of the webpage.

Now how do i goto each of these pages in order. What do I append with the address of this page to goto the three choices.

Replies are listed 'Best First'.
Re: Re: Re: Follow through POST method
by Corion (Patriarch) on May 05, 2004 at 10:55 UTC

    I am not sure how you come to the conclusion that you should have to append anything to the address of the page. My points 1. and 2. do not say anything about appending anything to any address of any page anywhere.

    Since I am lazy, I will show you how I attack the problem using the method described first, the easy translation of the Javascript code to Perl.

    Looking at the definition of the JavaScript __doPostBack routine, it mostly replaces ever $ by a : and then sets the fields __EVENTTARGET and __EVENTARGUMENT in the form to the passed values. So, to simulate a "click" on one of the region selections, one would have to set these fields correctly, too.

    use strict; use WWW::Mechanize; my $agent = WWW::Mechanize->new( autocheck => 1 ); sub __doPostBack { my ($eventTarget,$eventArgument) = @_; $agent->current_form->field('__EVENTTARGET',$eventTarget); $agent->current_form->field('__EVENTARGUMENT',$eventArgument); }; # ... load the page, and select the various zones

    I will not write the whole script for you. You now have to look through the input fields on $agent->current_form and look which zones are suitable for you and loop over these. You should understand how JavaScript works and how to analyze the code.

      Thanks for the prompt reply!!
      But things here may be simple for you, not for me. Not Complaining. I very much appreciate your help.

      The three regions in the code are actually three radio buttons. If either one is clicked it takes me to a new page. So how do i choose and click the radio button. The process for clicking a button is agent->click(); but what about the radio button. I read the www::mechanize page, but it is still not very clear to me.

      The code for the radio buttons is

      <table id="rdlZone" class="RBtnList" cellspacing="1" cellpadding="1" b +order="0"> <tr> <input id="rdlZone_0" type="radio" name="rdlZone" value="1" onclic +k="__doPostBack('rdlZone_0','')" language="javascript" /><label for=" +rdlZone_0">Chennai Madras</label> </tr> <tr> <td><input id="rdlZone_1" type="radio" name="rdlZone" value="2" on +click="__doPostBack('rdlZone_1','')" language="javascript" /><label f +or="rdlZone_1"></td>US Embassy New Delhi</label></td> </tr> <tr> <td><input id="rdlZone_2" type="radio" name="rdlZone" value="3" on +click="__doPostBack('rdlZone_2','')" language="javascript" /><label f +or="rdlZone_2"></td>Calcutta (Kolkata)</label></td> </tr> </table>

        Once again. You need to understand JavaScript, and how it interacts with the browser. First, visit the site you want to automate with JavaScript switched off. If the site works, then use the pages without JavaScript. Otherwise, you need to parse the HTML with HTML::Parser or get at the radio elements through the interface of HTML::Form, and then use the values of these elements together with the code I already outlined.

        Automating JavaScript-polluted pages is not easy, and you need to understand what the page exactly does before you can automate it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://350728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found