WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Current Open MSIE Screen

 Keywords: Grab Data From Current Open MSIE Screen Internet Explorer

Question:

There are a lot of examples how to grab data from MSIE by navigating to a specific URL by using OLE. What I want is to grab data from an already existing open page.

Answer:

So, you want to access a pre-existing instance of the internet explorer.

Code like this will allow you to get the document handle for the open session

objShell = CreateObject("Shell.Application")
objInstances = objShell.windows
objIE = 0
If objInstances.Count > 0 ; make sure we have instances open.
    ForEach objIE In objInstances
       sName = StrLower(objIE.FullName)
       If StrIndex( sName, 'iexplore.exe', 1, @FWDSCAN ) != 0 ; internet explorer not windows explorer.
        ret = AskYesNo( "Found instance of Internet Explorer ":objIE.LocationURL, "Would you like to view html?" )
        If ret
           objInstances = 0
           objShell = 0
           Break
        EndIf
      EndIf
    Next
EndIf
If objIE == 0
   Pause('Notice', 'Unable to locate any running instances of InternetExplorer')
EndIf

objDoc = objIE.Document
objMainhtml = objDoc.GetElementsbyTagname("HTML").item(0)
Pause('Webpage data', objMainhtml.innerhtml)
objMainhtml = 0
objDoc = 0
objIE = 0


Alternative Way (WinXp and older)

;Check to see if ClassID installed
myShellWindowsClsid="{9BA05972-F6A8-11CF-A442-00A0C90A8F39}" ;ShellWindows
myShellWindowsKey="AAA.TEST\CLSID"
If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
   RegSetValue(@REGCLASSES,myShellWindowsKey,myShellWindowsClsid)
   If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
      Message("CLSID Not installed.","Need Admin access")
      Exit
   EndIf
EndIf

SWs=ObjectCreate("AAA.TEST",1)
count=Sws.count
;message("Count",count)

For xx=0 To count-1
   windowobject=Sws.Item(xx)
   If windowobject.TopLevelContainer
      lu = windowobject.LocationURL
      ;message("Debug", strcat(windowobject.name, @crlf, windowobject.fullname))

      ;only grab MSIE windows
      If StrIndexNC(windowobject.fullname, "iexplore.exe", 1, @FWDSCAN) > 0
      ;If StrIndexNC(lu, "file://", 1, @FWDSCAN) != 0
         browserdoc = windowobject.document
          Break
      EndIf
   EndIf
   windowobject = 0
Next

;----------------------------------------------------------
; Here is how you save the HTML, once you have the correct MSIE window.
;----------------------------------------------------------
If browserdoc != 0
   mainhtml = browserdoc.GetElementsbyTagname("HTML")
   obj = mainhtml.item(0)
   srchfile = StrCat(DirScript(), "srch.html")
   If FileExist(srchfile) Then FileDelete(srchfile)
   oh = FileOpen(srchfile, "write")
   FileWrite(oh, obj.innerHTML)
   FileClose(oh)
EndIf
;Close open objects
mainhtml = 0
browserdoc = 0
SWs = 0

Article ID:   W15652
File Created: 2011:07:15:09:34:48
Last Updated: 2011:07:15:09:34:48