Retrieve HTML text from an IE ActiveX control Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
pizzapizze
Posts: 44
Joined: 08 May 2019, 15:38

Retrieve HTML text from an IE ActiveX control

14 Nov 2021, 18:59

Hey, I need to retrieve the text contents of a webpage, in an Internet Explorer ActiveX control.

So far, I tried retrieving it with things like

Code: Select all

IEObject.Document.body
but it doesn't work and is empty.

Here is the full code, but it's mainly pasted from the AHK Docs:

Code: Select all

Gui Add, Edit, w930 r1 vURL, https://www.autohotkey.com/boards/
Gui Add, Button, x+6 yp w44 Default, Go
Gui Add, ActiveX, xm w980 h640 vWB, Shell.Explorer
ComObjConnect(WB, WB_events)  ; Connect WB's events to the WB_events class object.
Gui Show
; Continue on to load the initial page:
WB.Silent := 1      ;Disabling annoying script errors
ButtonGo:
Gui Submit, NoHide
WB.Navigate(URL)
return

class WB_events
{
    NavigateComplete2(wb, NewURL)
    {
        GuiControl,, URL, %NewURL%  ; Update the URL edit control.
        msgbox % WB.Document.body.innerText     ;Empty
    }
DownloadBegin() {
}
}

GuiClose:
ExitApp
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Retrieve HTML text from an IE ActiveX control

14 Nov 2021, 19:23

Try DocumentComplete instead of NavigateComplete2.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Retrieve HTML text from an IE ActiveX control

14 Nov 2021, 19:49

Should work, show the code you are trying.
User avatar
pizzapizze
Posts: 44
Joined: 08 May 2019, 15:38

Re: Retrieve HTML text from an IE ActiveX control

14 Nov 2021, 22:01

Code: Select all

Gui Add, Edit, w930 r1 vURL, https://www.autohotkey.com/boards/
Gui Add, Button, x+6 yp w44 Default, Go
Gui Add, ActiveX, xm w980 h640 vWB, Shell.Explorer
ComObjConnect(WB, WB_events)  ; Connect WB's events to the WB_events class object.
Gui Show
; Continue on to load the initial page:
WB.Silent := 1      ;Disabling annoying script errors
ButtonGo:
Gui Submit, NoHide
WB.Navigate(URL)
return

class WB_events
{
    NavigateComplete2(wb, NewURL)
    {
        GuiControl,, URL, %NewURL%  ; Update the URL edit control.
        
    }
DownloadBegin() {
}
DocumentComplete() {
    msgbox % WB.Document.body.innerText     ; Still Empty
}
}

GuiClose:
ExitApp
This is the code. Did it really work for you? Could you retrieve something?
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Retrieve HTML text from an IE ActiveX control  Topic is solved

14 Nov 2021, 22:15

Must be

Code: Select all

DocumentComplete(WB) {
    msgbox % WB.Document.body.innerText
}
since WB is not global.
Anyway, you can do the same without connection to events:

Code: Select all

Gui Add, Edit, w930 r1 vURL, https://www.autohotkey.com/boards/
Gui Add, Button, x+6 yp w44 Default, Go
Gui Add, ActiveX, xm w980 h640 vWB, Shell.Explorer
; ComObjConnect(WB, WB_events)  ; Connect WB's events to the WB_events class object.
Gui Show
; Continue on to load the initial page:
WB.Silent := 1      ;Disabling annoying script errors
ButtonGo:
Gui Submit, NoHide
WB.Navigate(URL)
while WB.busy
   Sleep, 100
msgbox % WB.Document.body.innerText
return
User avatar
pizzapizze
Posts: 44
Joined: 08 May 2019, 15:38

Re: Retrieve HTML text from an IE ActiveX control

14 Nov 2021, 23:21

Nice thank you! It actually works.
I thought WB was global beacuse at the same line, I replaced it with WB.FullName and it displayed the AHK .exe path.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 355 guests