Jump to content

[BUG] ?? $oTag.GetAttribute doesn't give expected results afther $oIE.GoBack


 Share

Recommended Posts

Hello,

I try to get all the text from a news site around a subject.
The first run I get all the text inside a attribute in an array.
When i try to go back and reload another page it chrashes and think it because "$oIE.GoBack"
I couldn't find anything in the help/forum around this subject.
Do I need to reload the $oIE or something afther an X.GoBack?

The error i got is :

if $oTag2.GetAttribute("class") == "NewsDetail" Then
if $oTag2^ ERROR

I'm not shure why I got this error, maybe someone could explain?
Also I'm open for some pointers in this test script because I'm pretty new in working whit the IE.UDF :)
Maybe there is an simpler way to get the same results?

test script:

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

HotKeySet("{ESC}", "Terminate")

Global $oIE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france")

;get first subject
Global $oLink1 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl00_linkNews")
Sleep(500)
_IEAction($oLink1, "click")
Sleep(500)
Global $oTags = _IETagNameGetCollection($oIE, "div")
Global $aResults[1]
For $oTag In $oTags
    if $oTag.GetAttribute("class") == "NewsDetail" Then
        _ArrayAdd($aResults, $oTag.innerTEXT)
    EndIf
 Next
 $aResults[0] = UBound($aResults) - 1
 _ArrayDisplay($aResults, "Episodelist")
 ConsoleWrite($aResults[1] & @CRLF)
$oIE.GoBack

;get second subject
Global $oLink2 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl01_linkNews")
Sleep(500)
_IEAction($oLink2, "click")
Sleep(500)
Local $oTags2 = _IETagNameGetCollection($oIE, "div")
Local $aResults2[1]
For $oTag2 In $oTags2
    if $oTag2.GetAttribute("class") == "NewsDetail" Then
        _ArrayAdd($aResults2, $oTag2.innerTEXT)
    EndIf
 Next
 $aResults2[0] = UBound($aResults2) - 1
 ConsoleWrite($aResults2[1] & @CRLF)

Func Terminate()
    _IEQuit($oIE)
    Exit
EndFunc   ;==>Terminate

 

Edited by FMS

as finishing touch god created the dutch

Link to comment
Share on other sites

Hi @FMS

I cannot seem to reproduce your error, however my suggestion is to use Execute, like so:

if Execute('$oTag2.GetAttribute("class")') == "NewsDetail" Then

It usually prevents AutoIt from crashing.

Link to comment
Share on other sites

You don't get the class via an attribute...you get it via a property:

$sClass = $oTag2.className()
consolewrite($sClass & @crlf)

Also.  if you are going to navigate away from the page, you need to store the value prior to navigating.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

thanks for the tips, I've solved it like this :
 

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

HotKeySet("{ESC}", "Terminate")

;~ Global $aResults[1]
;~ Global $aDates[1]

Global $results[1][3] = [["date","rate","text"]]

fetch_text(1)
_ArrayDisplay($results, "$results" )

Func fetch_text($article_count = 1 )
   Local $temp_ar[1][3]
   Local $LinkObj
   Local $DateObj
   Local $Date
   Local $Tags
   $sleeptimer = 400
   Local $IE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france",0,0,1,1)
   Sleep( $sleeptimer )

   for $x = 0 to $article_count - 1
      $LinkObj = _IEGetObjById( $IE , "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl0" & $x & "_linkNews")
      $DateObj =_IEGetObjById( $IE , "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl0" & $x & "_Label1")
      $Date = _IEPropertyGet ( $DateObj , "innertext")
      $temp_ar[0][0] = $Date
      $temp_ar[0][1] = 0
      _IEAction($LinkObj, "click")
      Sleep( $sleeptimer )
      $Tags = _IETagNameGetCollection($IE, "div")

      For $Tag In $Tags
         if Execute('$Tag.GetAttribute("class")') == "NewsDetail" Then
            $temp_ar[0][2] = $Tag.innerTEXT
         EndIf
      Next
      _ArrayAdd($results, $temp_ar )
      $IE.GoBack
      Sleep( $sleeptimer )
   Next

   _IEQuit($IE)
EndFunc

 

Edited by FMS
code edit

as finishing touch god created the dutch

Link to comment
Share on other sites

Strangly enough the code above give's strange results but don't know what it is.
once in a while I get the folowing error, does anybody know why I get it?
Is it the code or is it a feature :D

==> The requested action with this object has failed.:
$IE.GoBack
$IE^ ERROR

 

as finishing touch god created the dutch

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

×
×
  • Create New...