Jump to content
Sign in to follow this  
fhanna

_IEAttach and _IEReadBodyText

Recommended Posts

fhanna

I am having problems reading the text from an IE window. I receive a 0 error return on the attachment but text is not returned; 0. Text is there, displayed and I can right click on the window and display the source. The following is an extract from the code with a couple of pauses. Could someone provide assistance?

Thank You.

sleep(5000)

#include <IE.au3>

$oIE = _IEAttach("")

sleep(5000)

msgbox(0,"",@error)

$Text = _IEBodyReadText($oIE)

msgbox(0,'',$Text)

Share this post


Link to post
Share on other sites
KaFu

You have to identify the instance of IE to attach to. If you've got only one open use

#include <IE.au3>
$oIE = _IEAttach ("", "instance", 1)
$Text = _IEBodyReadText($oIE)
msgbox(0,'',$Text)

otherwise read _IEAttach() help to identify Browser, maybe winlist() will help you too...

Share this post


Link to post
Share on other sites
fhanna

Thank you for your reponse and that did work. However, and after reading the _IEAttach documentation I am still having problems accomplishing what I want. I woudl not know what instance of a brower I want to attach to. I need to read the source of the currently displayed browser window that has focus. Simply utilizing the _IEReadBodyText does not return the source so attempted via an _IEAttach to the current window.

How do I retrieve the text from the currently displayed window. I have discovered utilizing a part of the wildow title will retrieve it but most titles have the url as the window title and will not work.

Long story short. Request assistance in retrieving text from currently displayed window without reference to the title or instance.

Thanks again.

Share this post


Link to post
Share on other sites
DaleHohm

You can use WinGetHandle("[active]") to get the handle of the active window, then pass that to _IEAttach()

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
fhanna

Thank you for your input. I still cannot get the text. I have tried the WinGetHandle then Attach with the same results. I have tried a _IEPropertyGet for the url and will not return.

If using a partial win title (if the http address is not the title) I can retrieve the text as with the instance. If using the current window to attach to I receive a 0 @error on the attach but a 3 for the _IEBodyReadText.

Please advise and thank you.

Share this post


Link to post
Share on other sites
DaleHohm

You'll want to run your code from SciTe, at least when you are testing with IE.au3 -- a lot of diagnostics written to the console.

the 3 is $_IEStatus_InvalidDataType which means the first parameter passed is not an object.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
fhanna

I'm really stumped!!! To keep it simple I created a simple .html page with the text: This is a test

Opended with IE and ran the following:

sleep(5000)

#include <ie.au3>

$oIE = _ieattach("")

sleep(2000)

$text = _iebodyreadtext($oie)

msgbox(0,"",$text)

and received the following:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\test.au3"

--> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch

--> IE.au3 V2.4-0 Error from function _IEBodyReadText, $_IEStatus_InvalidDataType

>Exit code: 0 Time: 8.601

I have also tried with wingethandle

Thanks again.

Share this post


Link to post
Share on other sites
Envoi

I'm really stumped!!! To keep it simple I created a simple .html page with the text: This is a test

Opended with IE and ran the following:

sleep(5000)

#include <ie.au3>

$oIE = _ieattach("")

sleep(2000)

$text = _iebodyreadtext($oie)

msgbox(0,"",$text)

and received the following:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\test.au3"

--> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch

--> IE.au3 V2.4-0 Error from function _IEBodyReadText, $_IEStatus_InvalidDataType

>Exit code: 0 Time: 8.601

...

How simple is this test page? Did you at least put <body> tags in it? If not, _IEBodyReadText will have no tag to get the .innertext from.

Share this post


Link to post
Share on other sites
DaleHohm

What makes you think you should pass "" to _IEAttach?


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
fhanna

I appreciate yo sticking with me on this. It is my assumption (good or bad) that a null "" would represent the currently focused window. I have used this quite extensively in my application and appears to work fine; maybe just luck. When a 0 @error return code is received the reason for this assumption. When trying the wingethandle I get exactly the same results.

I will be happy with any coding that will attach to the currently focused window without knowing the instance or other info. Is this possible and/or am I taking the right approach?

Thank you again.

Fred

Share this post


Link to post
Share on other sites
fhanna

I appreciate yo sticking with me on this. It is my assumption (good or bad) that a null "" would represent the currently focused window. I have used this quite extensively in my application and appears to work fine; maybe just luck. When a 0 @error return code is received the reason for this assumption. When trying the wingethandle I get exactly the same results.

I will be happy with any coding that will attach to the currently focused window without knowing the instance or other info. Is this possible and/or am I taking the right approach?

Thank you again.

Fred

BTW:

Is this the correct code for the wingethandle and attach?

$handle = wingethandle("[active]")

$oie = _ieattach($handle)

In both cases 0 is returned for @error

Share this post


Link to post
Share on other sites
KaFu

Read Help-File:

_IEAttach ( $s_string [, $s_mode = "Title" [, $i_instance = 1]] )

Thus

$handle = wingethandle("[ACTIVE]")
$oie = _ieattach($handle, "HWND")

would be correct (without testing).

Share this post


Link to post
Share on other sites
fhanna

Thank you both, Dale and Kafu. Dale was correct and KaFu confirmed my error. I honestly do read the documentation but without an exact sample can be confusing for me.

Again, I want to thank both of you and I will use the WinGetHandle routine.

Fred

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×