in reply to Re^3: WIN32::IE::Mechanize - can't follow link - JavaScript involved
in thread WIN32::IE::Mechanize - can't follow link - JavaScript involved
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: WIN32::IE::Mechanize - can't follow link - JavaScript involved
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 | |
It is because you make a GET and not a POST and you don't valorized some field. Replace this in your code:
and it will work. 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:37 UTC | |