Jump to content

Multiple LinkGetCollections in a nested loop


ade
 Share

Recommended Posts

Hello,

I have been searching the forums for help, of which I have found alot, but I am now at a dead end and cannot find any help hence my first post.

I have used _IELinkGetCollection successfully to get all links from a page and loop through them. I then nested the loop and called the function again but to a different variable. I now have 3 calls to the function in my loop using variables oLink, oSink and oTink.

While the oSink and oTink LinkGetCollections are not called the oLink loops through with no problem. However, as soon as the oSink and oTink collections are called and made the oLink variable creates a invalid function call argument.

At a guess I assume you can only have one collection in a loop. Is that correct? If so, how can I get around this? I thought about storing to an array but in the help it says the array can only store up to 21 values and I need over 200. What is the easiest solution to this problem?

Can someone please point me in the right direction.

Here is my code but with unnecessary lines taken out

$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")

For $oLink In $oLinks
    if StringRegExp($oLink.href, '/?owner') = 1 Then
        $oSinks = _IELinkGetCollection ($oIE)
        $iNumSinks = @extended
        MsgBox(0, "Link Info", $iNumSinks & " links found")
        For $oSink In $oSinks
            if StringRegExp($oSink.href, 'start=') =1 Then
                $PageTotal = $PageTotal + 1
            ;Do stuff
            EndIf
        Next
        For $i = 1 to $PageTotal
            $oTinks = _IELinkGetCollection ($oIE) 
            $iNumTinks = @extended
            For $oTink In $oTinks
                if StringRegExp($oTink.href, 'php?start') = 1 Then
                ;Do stuff
                EndIf
            Next 
        Next
    EndIf
;BY THIS POINT:: MsgBox(0, "oLink on end of loop =", $oLink.href) CREATES AN INVALID CALL ARGUMENT
;BUT ONLY AFTER THE "oSink" AND "oTink" COLLECTIONS HAVE BEEN MADE
Next
Link to comment
Share on other sites

Hello,

I have been searching the forums for help, of which I have found alot, but I am now at a dead end and cannot find any help hence my first post.

I have used _IELinkGetCollection successfully to get all links from a page and loop through them. I then nested the loop and called the function again but to a different variable. I now have 3 calls to the function in my loop using variables oLink, oSink and oTink.

While the oSink and oTink LinkGetCollections are not called the oLink loops through with no problem. However, as soon as the oSink and oTink collections are called and made the oLink variable creates a invalid function call argument.

At a guess I assume you can only have one collection in a loop. Is that correct? If so, how can I get around this? I thought about storing to an array but in the help it says the array can only store up to 21 values and I need over 200. What is the easiest solution to this problem?

Can someone please point me in the right direction.

I don't see the point in taking the same collection from the same $oIE instance over and over. Would this work better?

$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")

For $oLink In $oLinks
    If StringRegExp($oLink.href, '/?owner') = 1 Then
        For $oSink In $oLinks
            If StringRegExp($oSink.href, 'start=') = 1 Then
                ;Do stuff
                For $oTink In $oLinks
                    If StringRegExp($oTink.href, 'php?start') = 1 Then
                        ;Do stuff
                    EndIf
                Next
            EndIf
        Next
    EndIf
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for reply Psalty

Your method certainly looks better than my ham fisted attempt :)

However even with the amendment it still fails when it loops back into the oLink loop.

Could the problem be that each collection (oLink, oSink, oTink) is referencing the same instance of IE but different pages being displayed on the IE when the collections are taken?

I need to keep these collections even when the page is changed on the instance of IE as each collection has different link info

I have implemented a very dirty, longwinded method of copying each collection to its own global array and then using the global arrays. This works but i am certain that a much, much better method exists.

I am new and pretty much cluless when it comes to AutoIT so any advice is much appreciated. Any extra info you need, just ask and if I can I will post it.

Thanks

Link to comment
Share on other sites

Could the problem be that each collection (oLink, oSink, oTink) is referencing the same instance of IE but different pages being displayed on the IE when the collections are taken?

I need to keep these collections even when the page is changed on the instance of IE as each collection has different link info

I have implemented a very dirty, longwinded method of copying each collection to its own global array and then using the global arrays. This works but i am certain that a much, much better method exists.

I am new and pretty much cluless when it comes to AutoIT so any advice is much appreciated. Any extra info you need, just ask and if I can I will post it.

I would defer to Dale for details on the IE object model, but I'll bet navigating away from a page invalidates those objects.

As far as I can tell, you need to follow the links with another window (or another Tab, if IE7).

Start out with $oIE_1, $colLinks_1, and $oLink_1 for the first page. Use $oIE_2, $colLinks_2, and $oLink_2 for the page you were using $oSink for. Then use $oIE_3, $colLinks_3, and $oLink_3 for your $oTink page.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Yes, Psalty is correct. Once the document is destroyed, the link collection is invalid. Guessing what you are doing, it may also be possible for you to place the .href values in an array (the URLs of the links) and then you can navigate to them dirctly since the link collection will no longer be needed.

Regarding tabs, there is an undocumented function in IE.au3 called __IENavigate (undocumented = use at your own risk as it could change or disappear) that supports the use of tabs. See the source of IE.au3 or search the forums for it and you'll find some instructions.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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...