If you have JavaScript that submits the forms, you have the choice of two ways with WWW::Mechanize:
- (easy) Look at the JavaScript code and reprogram that functionality in the Perl code.
- (easy to hard) Use JavaScript::Spidermonkey to embed a JavaScript engine in your Perl program and run the Javascript code through that. You will have to supply appropriate wrappers so the browser DOM will be reflected in your WWW::Mechanize script. This can be very hard. See the first option for an alternative.
| [reply] |
<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. | [reply] [d/l] |
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. | [reply] [d/l] |