ControlSend and windows internet explorer problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

ControlSend and windows internet explorer problem

22 Sep 2017, 01:57

I would like to capture the text of a web page by using internet explorer in invisible mode but I can not get any results.

what's wrong with the code?

Code: Select all

clipboard =
base := "https://www.google.com"
IE := ComObjCreate("InternetExplorer.Application")
IE.Navigate(base)
Loop
  if (IE.readyState = 4)	; wait for page to load
     Break
ControlSend , Internet Explorer_Server1, ^a, ahk_class IEFrame
Sleep, 100
ControlSend , Internet Explorer_Server1, ^c, ahk_class IEFrame
ClipWait, 5			; wait for the clipboard to contain data
IE.Quit				;exit internet explorer window
MsgBox '%clipboard%'
[edited subject line]
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: ControlSend and windows explorer problem

22 Sep 2017, 02:11

If you use COM to grep some content from IE you should use it consistently.
Check out the forum for innerText/innerHTML/outerHTML
Good luck :)
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

Re: ControlSend and windows internet explorer problem

22 Sep 2017, 04:35

Thanks Bobo, I followed your input but the result is not what I expected: innertext returns unreadable text while I want to get what i manually get with ^a and ^c.
My sample code shows what I mean:

Code: Select all

clipboard =
base := "https://www.google.com"
IE := ComObjCreate("InternetExplorer.Application")
IE.Navigate(base)
Loop
  if (IE.readyState = 4)	; wait for page to load
     Break
Test := IE.document.body.innerText
IE.Quit				;exit internet explorer window
MsgBox '%Test%'
Maybe there is a way to get through the DOM what you get with ^a and ^c?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlSend and windows internet explorer problem

22 Sep 2017, 05:18

I managed to get this working on the Google homepage. When the input field is focused, I don't get the expected results, so I set the focus to a different element temporarily, and programmatically apply select all and copy. I also refocus the original active element at the end.

Code: Select all

q::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
MsgBox, % oWB.document.activeElement.tagName
MsgBox, % oWB.document.activeElement.id
oElt := oWB.document.activeElement
oWB.document.getElementByID("gb").focus()
Clipboard := ""
oWB.ExecWB(17, 0) ;OLECMDID_SELECTALL := 17
oWB.ExecWB(12, 0) ;OLECMDID_COPY := 12
oElt.focus()
ClipWait, 3
if ErrorLevel
	MsgBox, % "error"
else
	MsgBox, % Clipboard
oWB := oElt := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

Re: ControlSend and windows internet explorer problem

22 Sep 2017, 06:02

Hi jesswg ... I do not understand how the solution you are proposing can solve the issue:
capture the content of a web page, using the internet explorer invisible, as would be done with ^a and ^c.
Please explain me better with a code without hotkey how can I get this.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlSend and windows internet explorer problem

22 Sep 2017, 06:21

Here's a modified version of your script:

Code: Select all

clipboard =
base := "https://www.google.com"
IE := ComObjCreate("InternetExplorer.Application")
IE.Navigate(base)
Loop
  if (IE.readyState = 4)	; wait for page to load
     Break
;Test := IE.document.body.innerText

IE.document.getElementByID("gb").focus()
IE.ExecWB(17, 0) ;OLECMDID_SELECTALL := 17
IE.ExecWB(12, 0) ;OLECMDID_COPY := 12
ClipWait, 3
MsgBox, % Clipboard

IE.Quit				;exit internet explorer window
;MsgBox '%Test%'
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

Re: ControlSend and windows internet explorer problem

22 Sep 2017, 07:00

Thank you ! Thank you ! Thank you ! :superhappy: jeeswg :superhappy:
Only those who knew such cryptic commands could give the solution !
It works as I wanted and did not imagine that there could be such a cryptic way to do something apparently, I repeat apparently, so simple.
I would never have come to a solution without the support of a guru like you!
Now I'm going to study all the OLECMDID commands that I did not even know about!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, RussF and 315 guests