Jump to content
maniootek

Index of IE Collection COM Object

Recommended Posts

maniootek

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?

Share this post


Link to post
Share on other sites
Subz

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)

 

Share this post


Link to post
Share on other sites
maniootek

I knew it's something very easy! Thank you

Share this post


Link to post
Share on other sites
maniootek

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

 

Share this post


Link to post
Share on other sites
Juvigy
$oDiv

Is the current variable. You can get it inside the loop.

 

Share this post


Link to post
Share on other sites
maniootek

$oDiv is an object, how can I get index of it?

Share this post


Link to post
Share on other sites
Subz

You can just use:

For $i = 0 To $oDivs.length
    ConsoleWrite("Div index " & $i & "/" & $oDivs($i).innerhtml & @CRLF)
Next

 

Share this post


Link to post
Share on other sites
maniootek

This makes sense, thank you.

Edited by maniootek

Share this post


Link to post
Share on other sites
Juvigy

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.

Share this post


Link to post
Share on other sites
maniootek

2 script lines shorter :)

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

×