in reply to Re^2: WIN32::IE::Mechanize - can't follow link - JavaScript involved
in thread WIN32::IE::Mechanize - can't follow link - JavaScript involved
Near the beginning of the file, there are six lines:
<script type="text/javascript" language='Javascript' src='/IAPD/Inclu +des/Validation/Search/iapd_OrgSearch.js'></script> <script type="text/javascript" language='Javascript' src='/Iapd/ +Includes/iapd_WindowManagement.js'></script> <script type="text/javascript" language='Javascript' src='/Iapd/In +cludes/iapd_SetAndSub.js'></script> <script language=javascript>
that tell the browser to load the corresponding scripts (eg /IAPD/Includes/Validation/Search/iapd_OrgSearch.js and the other two). If you follow the links (they are relative to the URL from which you got the HTML page) you can get the scripts.
Then, in one the three scripts, you will find the javascript code which lays behind the page.
Reading better the HTML I see a strange thing:
<img SRC="/IAPD/Images/go_off.gif" alt="Go" name="go2" onMouseover="JImgAct('go2')" onMouseout="JImgInact('go2')" BORDER="0" align="top">
is the definition of the object that you call "Button GO2", but it is not a button, it is a image and I see handlers only for onMouseover and onMouseut (called when the mous pass over the image and when it exits from the image). For this to act as a button, it should have a handler for onClick, too.
Are you sure that this is the right object?
Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: WIN32::IE::Mechanize - can't follow link - JavaScript involved
by Ninth Prince (Acolyte) on May 22, 2008 at 18:10 UTC | |
No, I'm not sure, but it seems like the correct object to me. By way of background, this is a form that appears on the Securities and Exchange Commission's web site that investors can use to get information about investment advisors. The URL is http://www.adviserinfo.sec.gov/IAPD/Content/Search/iapd_OrgSearch.aspx. When I open this page up in a regular browser I fill in the field next to the label "CrdNumber" with a known value for an existing investment advisor (the value I use is 144549). To submit the form, I click on what looks like a "button" that is next to the field that I filled in. This process gets me to the page (information) that I really want. This is the process that I would like to automate over a large number of investment advisors Although I have never worked with JS, I have worked a little with Java, so it seemed odd to me that there was no "onClick()" method in the underlying source code. There was an earlier thread that I read that had a similar issue and the advice was that the object is not, in fact, a button. That thread suggested using ie->follow_link() which is why I tried adding it to my code. One other thing, although there are four (4) forms on the page, once I have filled in the CrdNumber field, if I click on ANY of the "submit" buttons (they all have different names) my submission works fine. The reasons for this are probably obvious to someone with more coding experience than myself, but it is a mystery to me. I'm going to try to follow those (relative) URLs from the JS lines. I will get back on that. Thanks for you advice. | [reply] [d/l] |
by psini (Deacon) on May 22, 2008 at 18:29 UTC | |
You are right> I didn't notice that the image tag was inside a <a HREF="JavaScript:JSubmitForm()" onMouseOver="status='Perform Search'; return true" onMouseOut="status='';"> tag. When you click the image, it its the HREF attribute that fires the jSubmitForm() sub from javascript. The "go" buttons are interchangeable because thet all call the same JS function. So we return to my previous post: if you get the linked javascript you'll find the source of the function:
As you can see, the function does nothing more than setting the hidden fields SearchType and NumRows to the appropriate values depending how the form was compiled and then submit the form. This means that you should be able to completely bypass the downloading of the form, and produce a simple GET with the correct parameters that retrieves directly the result you want. Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man. | [reply] [d/l] [select] |
by Ninth Prince (Acolyte) on May 22, 2008 at 19:39 UTC | |
Okay, here is what I tried (see below). When I run this I just get the original web page that contains the form, but with the values filled in. The form never "fires" (i.e., I'm not getting through to the next page that I actually want). Here is my code.
And here is the HTML that I get back.
| [reply] [d/l] [select] |
by psini (Deacon) on May 22, 2008 at 19:51 UTC | |
by Ninth Prince (Acolyte) on May 22, 2008 at 20:37 UTC | |
|
Re^4: WIN32::IE::Mechanize - can't follow link - JavaScript involved
by Ninth Prince (Acolyte) on May 22, 2008 at 18:33 UTC | |
Okay, I followed the JavaScipt script that looked like it would be the right one and I think it is. Here is the content. You can see that it includes the JSubmitForm() function call that appears in the "go2" button (that isn't a button!?).
With the JS code in hand, how do I attack my original problem of getting the form to submit? Thanks! | [reply] [d/l] |
by psini (Deacon) on May 22, 2008 at 19:01 UTC | |
Well, when you click (any)one of the "go" buttons, the jSubmitForm function populate the hidden fields of this form:
and submit it to the site. All you have to do is to prepare a POST statement with the fields correctly populated and submit it directly. I advise you to see the CGI module, with that you can do it with little more than 4 lines of perl. Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man. | [reply] [d/l] |
by Ninth Prince (Acolyte) on May 22, 2008 at 20:32 UTC | |
BINGO! Worked like a charm (using post). Thanks for your patience and all your help! | [reply] |