Jump to content

Loop at current object variable's position


Recommended Posts

An IE link collection $oLinks is being looped by a $oLink with a for-in loop. An if statement is used such that when the $oLink.href matches a string reg. exp., it will do a set of statements. The set of statements is this:

$a = 1
do
$matchpic = StringRegExp($oLink + $a.href, '(http://t2.imgchili.com/)(\d+)(\/)(\d+)(_)')
$a += 1
until $matchpic = 1

But the error is that $a is not an object variable.

After a match has been found, this $oLink is _paused_ at the current position inside this collection (I believe). How do I loop at the current $oLink?

Link to comment
Share on other sites

You are setting $a = 1 right before the do while loop. So, it is an normal variable (integer).

Second, are you sure to use the $oLink "plus" ... not & ?

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

You are setting $a = 1 right before the do while loop. So, it is an normal variable (integer).

Second, are you sure to use the $oLink "plus" ... not & ?

I need to declare the $a or else I'll get an error if I just leave the $a += 1 by itself.

Well I assume $oLink is some value. So $oLink + $a will be another value. Of course that wouldn't work so I need a way to loop through this current $oLink.

Link to comment
Share on other sites

Without knowing how you come up with $oLink, we can't really help you.

Here is an example of using the IE.au3 UDF:

#include <IE.au3>
$oIE = _IECreate("yoururl")
_IELoadWait($oIE)
$oColLinks = _IELinkGetCollection($oIE)
For $oLink In $oColLinks
 If StringRegExp($oLink.href, '(http://t2.imgchili.com/)(\d+)(\/)(\d+)(_)', 0) Then
  ; whatever you want to do
 EndIf
Next
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

For those of you who are confused, here's the part I'm talking about:

For $curr_page = $max_page To 1 Step -1
Local $oIE = _IECreate($page & $curr_page)
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended ;extends to the maximum value of links in $oLinks
$linkCol = _ExcelBookNew(1)
WinSetState($linkCol, "", @SW_SHOWMINIMIZED)

$lkcnt = 1 ;counts links

_ExcelWriteCell($linkCol, "@@@@@@@@@@ " & $page & $curr_page & " @@@@@@@@@@", $row, 1)

For $oLink In $oLinks ;"for a sub-object in the object"
$isMatched = StringRegExp($oLink.href, '(http://examplelink.com/articles/)(\d+)(\/)')
If $isMatched = 1 Then

_ExcelWriteCell($linkCol, $oLink.href, $lkcnt + 1, 2) ;writes link since row 2, and constantly on col 2

$a = 1
do
$matchpic = StringRegExp($oLink + $a.href, '(http://t2.imgchili.com/)(\d+)(\/)(\d+)(_)')
$a += 1
until $matchpic = 1
_ExcelWriteCell($linkCol, $oLink.href, $lkcnt + 1, 1) ;writes link since row 2, and constantly on col 1

EndIf
Next

_IEQuit($oIE)
Next
Edited by Relive
Link to comment
Share on other sites

I'm still not understanding what you need. Please explain it.

You cannot add 1 to the $oLink...it is an object, not a 'value'. What are you trying to accomplish by the $oLink + a.href...also, since a is not a dom object, you can't use the dom property .href on it...it's just an integer held in a variable.

Explain, very thoroughly, what your do loop is attempting.

edit: if the link's href is already matched on one URL, how are you able to match it to a second URL? Are you trying to continue the link collection loop, relative to the current match? You would need to do something like this for nested collection loops:

For $oLink In $oLinks ;"for a sub-object in the object"
$isMatched = StringRegExp($oLink.href, '')
If $isMatched = 1 Then
For $oLink_a in $oLinks
    ; your code
Next
EndIf
Next

here we go, i think this is what you need...you can use an integer to loop through the collection...I'm not aware of any property to get the current itteration from within a collection, but if you create your own integer to count that, you may then use that as your $i starting point:

Local $oIE = _IECreate("google.com")
 _IELoadWait($oIE)
 Local $oLinks = _IELinkGetCollection($oIE)
 For $i = 0 To $oLinks.length - 1
  ConsoleWrite($oLinks.item($i).href & @CRLF)
 Next
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

Thank you, very nice solutions. I wasn't aware of the other objects.

As I was awaiting replies, I also came up with a distinct solution:

_ExcelWriteCell($linkCol, "@@@@@@@@@@ " & $page & $curr_page & " @@@@@@@@@@", $row, 1)

Global $href_array[$iNumLinks]
$a = 0
For $oLink In $oLinks
$href_array[$a] = $oLink.href
;MsgBox(0, '', $href_array[$a])
$a += 1
Next

For $b = 0 To $iNumLinks-1 Step 1
$isMatched = StringRegExp($href_array[$b], '(http://examplelink.com/articles/)(\d+)(\/)')
If $isMatched = 1 Then

_ExcelWriteCell($linkCol, $href_array[$b], $lkcnt + 1, 2) ;writes link since row 2, and constantly on col 2

$d = 0
for $c = $b to $iNumLinks-1 Step 1 ;continues loop at $b
$matchpic = StringInStr($href_array[$c], "imgchili")
if $matchpic >= 1 then $d += 1
if $d = 3 then ExitLoop ;when done searching for the 3rd pic, exit this loop
next

_ExcelWriteCell($linkCol, $href_array[$c], $lkcnt + 1, 1) ;writes link since row 2, and constantly on col 1.
;range exceeds because the for loop went through the rest of the array...

EndIf
Next

The method used here is to loop through each $oLink.href while storing into each array index. From there, I can easily accomplish what I was trying to do in the first place.

Edited by Relive
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...