Sign in to follow this  
Followers 0
Mercury049

Getting Page Source Data from IE

6 posts in this topic

#1 ·  Posted (edited)

Hello All.

I would like to use the COM to get data from an Active window. Is this possible? I saw in the help on AutoIT I could use the COM to OPEN a page and get the source, but I need to get the source on an already open window. Is this possible? Is this the best method? If so, what do I need to do to get it? Below is what I've tried so far which is a miserable failure thus far.

winWaitActive("Window I am looking for - Microsoft Internet Explorer")
    
$actWind = WinActive("Manual Queue Detail - Microsoft Internet Explorer")
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("Get",$actWind)
$oHTTP.Send()
$HTMLSource = $oHTTP.Responsetext

UPDATE: After looking at my code I see that WinActive will only return a 1 if it is active, so this would NOT point the $oHTTP.Open statement to my active window. How can I do this?

Edited by Mercury049

Share this post


Link to post
Share on other sites

You need to use the IE COM object to access IE. If you are using HttpRequest, you don't connect through any browser.

Share this post


Link to post
Share on other sites

;

; get src of already openend page with regular browser

;

#include <GUIConstants.au3>

#include <IE.au3>

Global $oIE ;

#Region ### START Koda GUI section ### Form=

$Browser = GUICreate("Browser", 650, 450, 185, 145)

$btn_get = GUICtrlCreateButton("get src", 538, 24, 80, 21, 0)

GUISetState(@SW_SHOW)

#EndRegion ### START Koda GUI section ### Form=

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $btn_get

$oIE = _IEAttach("WINDOWS NAME") ; USE HERE WINDOW NAME !!

$my_text = _IEBodyReadHTML($oIE)

ClipPut($my_text);

MsgBox(0, "test", $my_text);

EndSelect

WEnd

GUIDelete()

Exit

Share this post


Link to post
Share on other sites

;

; get src of already openend page with regular browser

;

#include <GUIConstants.au3>

#include <IE.au3>

Global $oIE ;

#Region ### START Koda GUI section ### Form=

$Browser = GUICreate("Browser", 650, 450, 185, 145)

$btn_get = GUICtrlCreateButton("get src", 538, 24, 80, 21, 0)

GUISetState(@SW_SHOW)

#EndRegion ### START Koda GUI section ### Form=

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $btn_get

$oIE = _IEAttach("WINDOWS NAME") ; USE HERE WINDOW NAME !!

$my_text = _IEBodyReadHTML($oIE)

ClipPut($my_text);

MsgBox(0, "test", $my_text);

EndSelect

WEnd

GUIDelete()

Exit

Thank you both for your answers. I've tried working with the code above, but I keep getting a 0 returned. I have an "If" statement making sure I'm on the correct active window and I know there's a source to it because I can view it manually. Am I missing something?

Share this post


Link to post
Share on other sites

Thank you both for your answers. I've tried working with the code above, but I keep getting a 0 returned. I have an "If" statement making sure I'm on the correct active window and I know there's a source to it because I can view it manually. Am I missing something?

The default match mode for _IEAttach() is document title, which is not the same as window title. More reliable would be HWND:
$sWinTitle = "Window I am looking for - Microsoft Internet Explorer"
WinWaitActive($sWinTitle)
$hWin = WinGetHandle($sWinTitle) 
$oIE = _IEAttach($hWin, "hwnd")
$sHTML = _IEDocReadHTML($oIE)
MsgBox(64, "HTML", $sHTML)

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If this is a new issue, it is not wise to reopen a dormant topic.

More likely than an issue with new AutoIt verseion, it is likely that you have a browser process in an odd state on your system. Please insure there are no iexplore.exe processes running on your system and try again or logout/reboot to see if the problem disappears.

Dale

Edited by DaleHohm

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

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  
Followers 0