Sign in to follow this  
Followers 0
Relive

Loop at current object variable's position

7 posts in this topic

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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Eli_jahbot
      By Eli_jahbot
      My esteemed Autoits I need your help once again.
      I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. 
      Here is what Im trying to do:
      -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc.
      -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it.
      Here is my feeble attempt that obviously fails:
      #include <msgboxconstants.au3>
      #include <Constants.au3>
      #include <array.au3>
      Login()
      Func Login()
          local $array[30] = ["10", "11", "12",etc etc]
          ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","")
          Local $userid = InputBox("ERx Login", "What is your username?", "", "")
          Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*")
      for $1 = 1 to 30(I need to do the same steps in 30 different apps)
      run("Z:launch.exe")
      WinWaitActive("Input")
      Send (Sequential ARRAY VALUE HERE)
      Send("{ENTER}")
      WinWaitActive("window")
      Send($userid)
      Send("{TAB}")
      send($Passwd)
      Send("{ENTER}")
      WinWaitActive("[CLASS:SunAwtDialog]")
      Sleep(500)
      WinClose("Home Page")
      Next
      EndFunc
       
      your help is greatly appreciated.
      Thanks for your time
    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?