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

    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks