[Solved] how to retrieve the HTML code from IE
Posted: Tue Feb 19, 2019 11:38 am
Hello, I can get the html code of Internet Explorer when it is opened by the program. but how to do it when Internet Explorer is already open?
thank you
sorry for my english, I'm french
thank you
Code: Select all
;***COMate*** COM automation through iDispatch.
;*===========
;*
;*Web gadget demo. (Advanced users!) Based upon code by hm.
;*
;*This demo not only shows how to obtain a COMateObject from a web-gadget, but also sets a 'global' event handler.
;*
;*This demo also shows how to over-ride the COMateObject SetEventHandler() method and direct COMate to seek out a specific
;*'out-going interface'. Left to it's own devices, COMatePLUS will utilise the first suitable 'connection point' and out-going interface
;*that it encounters. In the case of a web gadget, we direct COMatePLUS to directly seek out a connection point for the newer DWebBrowserEvents2
;*interface.
;*I did state that this demo is for advanced users!
;/////////////////////////////////////////////////////////////////////////////////
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
Global browser.COMateObject
Global document.COMateObject
Global frames.COMateObject
Global eventName$
Declare GetHtml()
;/////////////////////////////////////////////////////////////////////////////////
;The following is our event callback for our web-gadget object.
;The 'Object' parameter will contain the COMate object upon which was used the \SetEventHandler() method; in our case it will point
;to our browser object.
Procedure EventProc(Object.COMateObject, eventName$, parameterCount)
Debug eventName$
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
Procedure GetHtml()
document = browser\GetObjectProperty("Document") : Debug "document :"+document
If document
frames = document\GetObjectProperty("frames") : Debug "frames :"+frames
If frames
Debug document\GetStringProperty("Head\InnerHtml")
Debug document\GetStringProperty("Body\InnerHtml")
EndIf
EndIf
EndProcedure
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 130, 60, "WebGadget Events Test", #PB_Window_SystemMenu | #PB_Window_TitleBar )
StickyWindow(0,1)
ButtonGadget(1, 10, 10, 110, 40, "GetHTML")
; hwnd = FindWindow_("IEFrame",0) : Debug hwnd
; browser = COMate_WrapCOMObject(GetWindowLongPtr_(hwnd, #GWL_USERDATA))
browser = COMate_CreateObject("InternetExplorer.Application")
browser\SetProperty("Visible = #true")
browser\invoke("Navigate('http://www.purebasic.com')")
Debug browser
;Set the 'global' event handler for the browser object.
;In order to over-ride COMatePLUS' selection of 'connection point' we pass a pointer to the IID of the DWebBrowserEvents2 out-going interface
;within the second optional parameter.
If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
browser\SetEventHandler(#COMate_CatchAllEvents, @EventProc(), 0, iid)
EndIf
EndIf
Repeat
Until browser\GetIntegerProperty("ReadyState") = 4
If browser
document = browser\GetObjectProperty("Document") : Debug "document :"+document
If document
frames = document\GetObjectProperty("frames") : Debug "frames :"+frames
If frames
Debug document\GetStringProperty("Head\InnerHtml")
Debug document\GetStringProperty("Body\InnerHtml")
EndIf
EndIf
EndIf
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case 1
GetHtml()
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
frames\Release()
document\Release()
browser\Release()