Sign in to follow this  
Followers 0
mred589

Internet Explorer COM

11 posts in this topic

How do I access the information on a page in internet explorer when it's hidden? I guess that there is some way to do this through the com object but I don't know what the exact command would be.

I am trying to make autoit open a page, click the submit button, then read the page that follows. I've got the first two done, but I'm a little lost as how to do the third. Thanks in advance for any help.

Share this post


Link to post
Share on other sites



.document.documentelement.outerHTML

this will give you pretty much everything on that page.

just make sure to have the page loaded.

I give a lot of examples and such in scraps. (IE Fun Part #)

basically do your submit and then

while $IEobject.busy

tooltip("loading")

sleep(10)

WEnd

$IEresult= $IEobject.document.documentelement.outerHTML

msgbox(1,"html of page",$IEresult)


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

.document.documentelement.outerHTML

this will give you pretty much everything on that page.

just make sure to have the page loaded.

I give a lot of examples and such in scraps. (IE Fun Part #)

basically do your submit and then

while $IEobject.busy

  tooltip("loading")

  sleep(10)

WEnd

$IEresult= $IEobject.document.documentelement.outerHTML

msgbox(1,"html of page",$IEresult)

<{POST_SNAPBACK}>

This code works great on stuff that is in HTML format. But It won't return anything when your viewing an XML file. Is there another line that will read me the XML code?

Share this post


Link to post
Share on other sites

$ObjIE=ObjCreate("InternetExplorer.Application")
$ObjIE.navigate("http://hardware.slashdot.org/hardware.rss"); XML rss feed
$ObjIE.visible=1
Do
sleep(20)
until NOT $ObjIE.busy
msgbox(1,"",$ObjIE.document.body.innerhtml)

do you have an example site it doesn't work on?


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

$ObjIE=ObjCreate("InternetExplorer.Application")
$ObjIE.navigate("http://hardware.slashdot.org/hardware.rss"); XML rss feed
$ObjIE.visible=1
Do
sleep(20)
until NOT $ObjIE.busy
msgbox(1,"",$ObjIE.document.body.innerhtml)

do you have an example site it doesn't work on?

<{POST_SNAPBACK}>

This is the page I am trying to get up. When I run the script it opens the first page just fine, then clicks on the submit button. From there the page I attached comes up. THe script stays running for another ten seconds after the page has loaded then dies without an error. Here is the code I am using so far.

;Access Upcoming Shows
Const $URL = @ScriptDir&"\Logon.html"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith

With $ObjIE2.document.forms(2)
  .submit()
EndWith
while $ObjIE2.busy
tooltip("loading")
sleep(10)
WEnd

MsgBox (0, "test", $ObjIE2.document.documentelement.outerHTML )

This page I am trying to access is an API for beyond TV to access a list of recording shows.

GetUpcomingRecordings.xml

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The problem is that you go beyond what the standard msgbox can handle for data.

I downloaded your file, and ran some tests. A smaller file works fine (make sure to parse the XML correctly)

This will work with your full file, but you will see it takes a while, and that I was playing with two files to make sure it worked correctly.

;Access Upcoming Shows
Const $URL = @ScriptDir&"\GetUpcomingRecordings_big.xml"
;Const $URL = @ScriptDir&"\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
;$giant=stringlen($ObjIE2.document.documentelement.innerHTML)
;msgbox(1,"",$giant)

#include <GUIConstants.au3>

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit ("Wait a bit"& @CRLF, 1,2,350,397,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

; will be append dont' forget 3rd parameter
GUICtrlSetData ($myedit, $ObjIE2.document.documentelement.outerHTML,1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Exit

Also, looking that this is XML, you should be able to use the text displayed perhapse.

Your data went beyond even the edit box this way, so I split into 2 parts.

In your script, you will have to set up some delays, because IE takes some time to pass back this amount of data, as shown in the code above.

When IE is asked to pass only the text it is far faster, and with XML, it might be just as easy to work with.

;Access Upcoming Shows
Const $URL = @ScriptDir&"\GetUpcomingRecordings_big.xml"
;Const $URL = @ScriptDir&"\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
;$giant=stringlen($ObjIE2.document.documentelement.innerHTML)
;msgbox(1,"",$giant)

#include <GUIConstants.au3>

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit (Stringtrimright($ObjIE2.document.documentelement.outertext,10000)& @CRLF, 1,2,350,197,$ES_AUTOVSCROLL+$WS_VSCROLL)
$myedi2=GUICtrlCreateEdit (Stringright($ObjIE2.document.documentelement.outertext,10000),1,198,350,197,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Exit
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

The problem is that you go beyond what the standard msgbox can handle for data.

I downloaded your file, and ran some tests.  A smaller file works fine (make sure to parse the XML correctly)

This will work with your full file, but you will see it takes a while, and that I was playing with two files to make sure it worked correctly.

;Access Upcoming Shows
Const $URL = @ScriptDir&"\GetUpcomingRecordings_big.xml"
;Const $URL = @ScriptDir&"\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
;$giant=stringlen($ObjIE2.document.documentelement.innerHTML)
;msgbox(1,"",$giant)

#include <GUIConstants.au3>

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit ("Wait a bit"& @CRLF, 1,2,350,397,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

; will be append dont' forget 3rd parameter
GUICtrlSetData ($myedit, $ObjIE2.document.documentelement.outerHTML,1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Exit

Also, looking that this is XML, you should be able to use the text displayed perhapse.

Your data went beyond even the edit box this way, so I split into 2 parts.

In your script, you will have to set up some delays, because IE takes some time to pass back this amount of data, as shown in the code above.

When IE is asked to pass only the text it is far faster, and with XML, it might be just as easy to work with.

;Access Upcoming Shows
Const $URL = @ScriptDir&"\GetUpcomingRecordings_big.xml"
;Const $URL = @ScriptDir&"\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
;$giant=stringlen($ObjIE2.document.documentelement.innerHTML)
;msgbox(1,"",$giant)

#include <GUIConstants.au3>

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit (Stringtrimright($ObjIE2.document.documentelement.outertext,10000)& @CRLF, 1,2,350,197,$ES_AUTOVSCROLL+$WS_VSCROLL)
$myedi2=GUICtrlCreateEdit (Stringright($ObjIE2.document.documentelement.outertext,10000),1,198,350,197,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Exit

<{POST_SNAPBACK}>

Can I just take this output and put it into a text file? I don't want to run into any more errors where the string is too long. Also, when I pause it to wait for IE to dump the data, can I just run the same while loop? Thanks for all your help.

while $ObjIE2.busy
tooltip("loading")
sleep(10)
WEnd

Share this post


Link to post
Share on other sites

I prefer:

Do
    Sleep(50)
  Until .ReadyState = 4

but sure, you can use filewrite()

;Access Upcoming Shows
Const $URL = @ScriptDir & "\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
filedelete("myfilename.xml"); so it is blank and doens't just add to the file.
FileWrite("myfilename.xml",$ObjIE2.document.documentelement.outertext)

well something like that :evil:

of course add your code to actually navigate to the live feed first. :)


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I prefer:

Do
    Sleep(50)
  Until .ReadyState = 4

but sure, you can use filewrite()

;Access Upcoming Shows
Const $URL = @ScriptDir & "\GetUpcomingRecordings.xml"

$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
sleep(1000)
filedelete("myfilename.xml"); so it is blank and doens't just add to the file.
FileWrite("myfilename.xml",$ObjIE2.document.documentelement.outertext)

well something like that :evil:

of course add your code to actually navigate to the live feed first.  :)

<{POST_SNAPBACK}>

I tried it but it doesn't work. It doesn't write the file and exits without any errors. Here is the code I'm using right now.

;Access Upcoming Shows


$ObjIE2=ObjCreate("InternetExplorer.Application")

With $ObjIE2
  .Visible = True
  .Navigate($URL)
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith

With $ObjIE2.document.forms(2)
  .submit()
EndWith
while $ObjIE2.busy
sleep(10)
WEnd
sleep(1000)

filedelete("upcoming.xml"); so it is blank and doens't just add to the file.
FileWrite("upcoming.xml",$ObjIE2.document.documentelement.outertext)

Another length error?

Share this post


Link to post
Share on other sites

I don't know if this matters, but the size will change each time the file is accessed.

Share this post


Link to post
Share on other sites

Hi,

I,m a beginner, but my understanding of FileWrite;

  #include <file.au3>

              $Html1=$ObjIE.document.documentelement.outerHTML

$sFilePath1=@ScripDir&"\html1.txt"

_FileCreate ( $sFilePath1 )

FileOpen($sFilePath1,1 )

FileWrite($sFilePath1,$Html1 )

FileClose($sFilePath1)

This works for html from a simple site?

Randall

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