maniootek Posted February 16, 2017 Posted February 16, 2017 Is there any method for collection com object which define which exact object you want to retreive? I tried use ".index()" method but it didn't worked. Let me explain my problem with code sample: Local $aTbodys[0][7] $oTbodys = _IETagnameGetCollection($oIE, "tbody") for $oTbody In $oTbodys $date = _IETagnameGetCollection($oTbodys, "div", 2).innerhtml $name = _IETagnameGetCollection($oTbody, "div", 3).innerhtml $surname = _IETagnameGetCollection($oTbody, "div", 4).innerhtml $title = _IETagnameGetCollection($oTbody, "div", 5).innerhtml $comment1 = _IETagnameGetCollection($oTbody, "div", 6).innerhtml $comment2 = _IETagnameGetCollection($oTbody, "div", 7).innerhtml $comment3 = _IETagnameGetCollection($oTbody, "div", 8).innerhtml _ArrayAdd($aTbodys, $date & "|" & $name & "|" & $surname & "|" & $title & "|" & $comment1 & "|" & $comment2 & "|" & $comment3) next _ArrayDisplay($aTbodys) I want to optimize speed of processing the data and I belive, that it could be done by replacing multiple used _IETagnameGetCollection() function with only one Local $aTbodys[0][7] $oTbodys = _IETagnameGetCollection($oIE, "tbody") for $oTbody In $oTbodys $oDivs = _IETagnameGetCollection($oTbodys, "div") $date = $oDivs.index(2).innerhtml $name = $oDivs.index(3).innerhtml $surname = $oDivs.index(4).innerhtml $title = $oDivs.index(5).innerhtml $comment1 = $oDivs.index(6).innerhtml $comment2 = $oDivs.index(7).innerhtml $comment3 = $oDivs.index(8).innerhtml _ArrayAdd($aTbodys, $date & "|" & $name & "|" & $surname & "|" & $title & "|" & $comment1 & "|" & $comment2 & "|" & $comment3) next _ArrayDisplay($aTbodys) Above code does not work. It only shows my conception. Of course I can add each object to array and use array index to get what I need but it does not optimize the speed. Any idea?
Subz Posted February 16, 2017 Posted February 16, 2017 You mean like: Local $aTbodys[0][7] $oTbodys = _IETagnameGetCollection($oIE, "tbody") for $oTbody In $oTbodys $oDivs = _IETagnameGetCollection($oTbodys, "div") $date = $oDivs(2).innerhtml $name = $oDivs(3).innerhtml $surname = $oDivs(4).innerhtml $title = $oDivs(5).innerhtml $comment1 = $oDivs(6).innerhtml $comment2 = $oDivs(7).innerhtml $comment3 = $oDivs(8).innerhtml _ArrayAdd($aTbodys, $date & "|" & $name & "|" & $surname & "|" & $title & "|" & $comment1 & "|" & $comment2 & "|" & $comment3) next _ArrayDisplay($aTbodys)
maniootek Posted February 16, 2017 Author Posted February 16, 2017 I knew it's something very easy! Thank you
maniootek Posted February 21, 2017 Author Posted February 21, 2017 when I am in loop of collection elements, how to get current element index without using "helping variable" ($counter) ? $oDivs = _IETagnameGetCollection($oIE, "div") $counter = 0 For $oDiv in $oDivs ConsoleWrite("Div index " & $counter & "/" & $oDivs.length & @CRLF) $counter += 1 Next
Juvigy Posted February 21, 2017 Posted February 21, 2017 $oDiv Is the current variable. You can get it inside the loop.
maniootek Posted February 21, 2017 Author Posted February 21, 2017 $oDiv is an object, how can I get index of it?
Subz Posted February 21, 2017 Posted February 21, 2017 You can just use: For $i = 0 To $oDivs.length ConsoleWrite("Div index " & $i & "/" & $oDivs($i).innerhtml & @CRLF) Next
maniootek Posted February 21, 2017 Author Posted February 21, 2017 (edited) This makes sense, thank you. Edited February 21, 2017 by maniootek
Juvigy Posted February 22, 2017 Posted February 22, 2017 This is just the same thing. $I is the same as $counter. Why do you think there is a difference? I don't get it.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now