Link to home
Start Free TrialLog in
Avatar of GrahamSkan
GrahamSkanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Screenscrape: referenced JavaScript procedure missing from HTML

I am trying to drive a screenscraping program and have problem with a collected list. If the list is too long for the listing page, a First, Previous, Next, Last series of links is displayed to allow the user to navigate the list.

The links refer to Javascript procedures.

<tr class="OneLinerHFLText">
<td width="30%" colspan="30" align="left" valign="top" style="padding-top:2" >
<a class="OneLinerHFLink" HREF="javascript:top.frames[0].PrintPreview();">Print Preview</a>&nbsp;|&nbsp;<a class="OneLinerHFLink" href="javascript:window.history.go(0-1)"">Revise Search</a></td>
<td width="70%" colspan="70" align="right" valign="top" style="padding-top:2" >
 Listings <span Class="PrintHidden">1 - 50 of 54 </span>&nbsp;|&nbsp;First&nbsp;|&nbsp;Previous&nbsp;|&nbsp;<A class="OneLinerHFLink" HREF='javascript:GetNext(51,51)'>Next</A>
&nbsp;|&nbsp;<A class="OneLinerHFLink" HREF='javascript:GetNext(5,5)'>Last</A>
</td>
</tr>

I run this line
WebBrowser1.document.frames(1).execScript GetNext(51, 51), "JavaScript"

and I get 'Sub or Function not defined' with 'GetNext' highlighted.

Certainly I can't find that javascript procedure in the HTML on the page which has two frames and uses stylesheets. Where could it be and, more importantly, how can I call it?
Avatar of DreamMaster
DreamMaster

WebBrowser1.document.Window.Frames[1].execScript GetNext(51,51), "JavaScript"

that should work...

Regards,
Max.
Avatar of GrahamSkan

ASKER

The square brackets cause a syntax error, so I've changed them to ().
But I get the same error.
(Still 'Sub or Function not defined')
You are not sure where the function is you said?

Try if  you can even call Webbrowser1.document.window.frames(1) at all...

Also you can view the source I take it? If so you might reference to the frame using it's name...

Regards,
Max.
Hi Max.
I've looked in the page source and in the source for both frames. There is only a call, and no source for the script. But it works if I click on it.

This returns 1045
WebBrowser1.document.frames(1).document.all.length
as does this:
WebBrowser1.document.frames("mainn").document.all.length

but these give error 438 (Object doesn't support this property or method).
WebBrowser1.document.window.frames(1).document.all.length
WebBrowser1.document.window.frames("mainn").document.all.length
Yes I can view the source. I can only find the call to the script in the HREF, not the script itself. I have looked in the other frame as well.
Well...then that's likely the source of your problems...how about the frameset itsself? Could be the function is defined in there...

Regards,
Max.
Hi Max,
Thanks for you help and interest so far.
Unless there is some magic method of getting javascript from the server, logic says that it must exist on the page somewhere, or perhaps that's just dummy code and the real action is hidden somehow.

This is the page source obtained using the Firefox browser. Is that what you mean, or is there a frameset object that I should get.

<html>
<head>
      <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
      <meta name="ProgId" content="FrontPage.Editor.Document">
      <title>MLSAlliance™ Home Page</title>
</head>

<frameset framespacing="0" frameborder="0" border="0" cols="85,*">
  <frame name="contents" target="mainn" src="FrameBar4.asp" borderColor="#FFFFFF" marginwidth="0" marginheight="0" scrolling="no" noresize>
  <frame name="mainn" src="apps/search/MapServer.asp" marginwidth="0" marginheight="0" borderColor="#FFFFFF">

  <noframes>
        <body bgcolor="#FFFFFF">
              <p>This web page uses frames, but your browser doesn't support them. Please use a browser that supports frames.</p>
        </body>
  </noframes>
</frameset>

</html>

Graham
ASKER CERTIFIED SOLUTION
Avatar of DreamMaster
DreamMaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Bingo.

This worked OK.

Call WebBrowser1.document.frames(1).GetNext(51, 51)

Should that syntax always work? It is neater than using execScript.
Yes...as long as the reference to the frame is made, you can call any function that's defined in it...

Regards,
Max.
Max,
Thanks for your help
Regards, Graham
>>I can only find the call to the script in the HREF, not the script itself. I have looked in the other frame as well
look for a reference in the head, something like

<script language="JavaScript" type="text/javascript" src="path/to/file.js">

this will have teh source javascript

not exactly what you are looking for but might be helpful

<script language="JavaScript" type="text/javascript" src="">
      var str="";
      for (x=0;x<document.links.length;x++){
            if(document.links[x].href.indexOf('GetNext')!=-1){
                  alert(document.links[x].href.replace(/javascript:/,""));
            }
      }
</script>
<script language="VBScript">
      for x=0 to document.links.length
            if(InStr(document.links(x).href, "GetNext")) then
                  msgbox Replace(document.links(x).href, "javascript:", "")
            end if
      next x
</script>
No problem, just glad I could help.. :)

Regards,
Max.
Jester_48, thanks for the extra bit of information.