Jump to content

Problem getting body with _IEBodyReadText


VeryGary
 Share

Recommended Posts

#include <IE.au3>
Local $oIE = _CreateIE ()
Local $iCounter

ConsoleWrite ( "Loading Google" )

_IENavigate ( $oIE, "https://www.google.com/", 0 )
$iCounter = 0
While Not StringInStr ( _IEBodyReadText ( $oIE ), "Feeling Lucky", 2 )
   Sleep ( 1000 )
   $iCounter = $iCounter + 1
   ConsoleWrite ( "." )
   If $iCounter > 30 Then
      ConsoleWrite ( @CRLF & _IEBodyReadText ( $oIE ) & @CRLF )
      ExitLoop
   EndIf
WEnd


Func _CreateIE()
   Local $iRegKeyFlag, $sRegKey

   $sRegKey = RegRead ('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging')
   If @error <> 0 Then $iRegKeyFlag = 1

   ; make internet explorer not share session data between tabs/windows. hopefully this isolates windows.
   RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging','REG_DWORD','00000000')

   Local $hWnd = 0
   While $hWnd = 0
      ; hack to be able to locate correct IE window. load page that displays server environment variables and seed a variable with a random key value.
      Local $sRand = Random ( 2^16+1, 2^31-1, 1)
      Run('"C:\Program Files (x86)\Internet Explorer\iexplore.exe" -nosessionmerging -private http://www.all-nettools.com/toolbox/environmental-variables-test.php?' & $sRand )
      $hWnd = WinWait ( "", "http://www.all-nettools.com/toolbox/environmental-variables-test.php?" & $sRand, 10)
      If $hWnd <> 0 Then $oIE = _IEAttach ( $hWnd, "hwnd" )
   WEnd

   ; set it back to what it was before.
   If $iRegKeyFlag <> 1 Then
      RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging','REG_DWORD', $sRegKey)
   Else
      RegDelete ('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging')
   EndIf
   Return $oIE
EndFunc

 

When I run the above code, _IEBodyReadText () returns the body for the prior (all-nettools) page, even when the new page is fully loaded and in good readyState. Not Google as expected.  I am using IE 11 on 64bit Win 7.

How to get actual body text?

Edited by VeryGary
Link to comment
Share on other sites

... And now it's working.  Fought with this for an hour and posted then it decides to work properly.  IE, I hate you.

 

Edit: I spoke too soon. This must be some kind of race condition that poisons the text property with the previously loaded page if it's called while the 1st page is loaded and the 2nd is loading or something. (That is, IE thinks the URL is the second page, but it reads the body from the first page, then it sets the property thinking all is good and doesn't rewrite the property once the page is actually back to readystate.)

Is there a way to reset the full DOM after I'm done with the first page or something?  Maybe force IE to rewrite properties?

Edit again: Putting a "_IENavigate ( $oIE, "about:blank", 0 )" before loading the google page seems to fix it... ?

Edited by VeryGary
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...