Jump to content

need a little help building an array


RickB75
 Share

Recommended Posts

Guys,

      For the life of me, I can figure out how to do this simple task. I want to populate an array with a list of links. I can populate the array with one link at the time but for the main part of my script I need the full list of links so I can use a Ubound to count through them.

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/")
Local $links =  _IELinkGetCollection($oIE)

    For $link In $links
        
        If StringInStr($link.href,"http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
            ConsoleWrite("Link Found: " & $Link.href & @CRLF)

            $linkarray = StringSplit($link.href,' ',2)

        EndIf
    Next
_ArrayDisplay($linkarray)

What am I missing here guys???

Link to comment
Share on other sites

Look at the function _StringBetween()

Something like.

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/")
Local $code = _IEBodyReadHTML($oIE)

$aLinks = _StringBetween($code, 'http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=', '"')

_ArrayDisplay($aLinks)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thanks John! That is one way to do it that I didn't think of. Can you show me how to build the array with the string data. I will use your example in my main script this time but I really want to learn how to build the array. I have other scripts that this would be useful on. I tried using the _ArrayAdd function but I could not get it to work. I was thinking that I could use some thing like this

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/")
Local $links =  _IELinkGetCollection($oIE)
Global $myarray
    For $link In $links
        
        If StringInStr($link.href,"http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
            ConsoleWrite("Link Found: " & $Link.href & @CRLF)

            Local $linkarray = StringSplit($link.href,' ')

        EndIf

        _Arrayadd ($myarray,$linkarray)
    Next
_ArrayDisplay($myarray)

and I could not get that to work. Also, I tried using this _ArrayAdd($myarray, $link.href) but that didn't work either.

Link to comment
Share on other sites

Probably something like....

#include <IE.au3>
#include <Array.au3>

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/")
Local $links = _IELinkGetCollection($oIE)
Global $myarray
For $link In $links

    If StringInStr($link.href, "http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
        ConsoleWrite("Link Found: " & $Link.href & @CRLF)
        _ArrayAdd($myarray, $link.href)
    EndIf

Next
_ArrayDisplay($myarray)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

That's exactly what I thought but I keep getting an error. If I understand the help file correctly, I should be able to use _ArrayAdd($myarray,"my value here") and it should insert it at the end of $myarray. Question??? Am I declaring the array incorrectly?

Link to comment
Share on other sites

Not sure, try...

#include <IE.au3>
#include <Array.au3>

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/")
Local $links = _IELinkGetCollection($oIE)
Global $myarray[1] = 1
For $link In $links

    If StringInStr($link.href, "http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
        ConsoleWrite("Link Found: " & $Link.href & @CRLF)
        _ArrayAdd($myarray, $link.href)
        $myarray[UBound($myarray)-1] += 1
    EndIf

Next
_ArrayDisplay($myarray)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

RickB75,

Try this.  See comments in code...

#include <ie.au3>
#include <array.au3>

local $aLinks[1]                                        ; declare your array with one entry

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/",0,0)
Local $links =  _IELinkGetCollection($oIE)

    For $link In $links

        If StringInStr($link.href,"http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
            ConsoleWrite("Link Found: " & $Link.href & @CRLF)

            $aLinks[ubound($aLinks)-1] = $link.href     ; add the link to your array
            redim $aLinks[ubound($aLinks)+1]            ; increase array by one

        EndIf
    Next
_ArrayDisplay($aLinks)

kylomas

edit: I also supressed display of the WEB site...I see J1 got in before me...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

that's it. I just made the variable into an array. $myarray[1] = ["text"] and it worked perfectly. Is this the only way to declare an array before you actually use it???

Yeah sorry about that, my mistake.

Depends what function is using it I suppose.

I'd keep $myarray[1] = [0], that way $myarray[0] should should always hold the count of links found.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I like it like this, so your array is always perfectly defined (no empty bounds)...but that's just personal pref...another way, would be to delete the UBound dim, after you exit the for loop (kylomas sample)

#include <ie.au3>
#include <array.au3>

local $aLinks                                       ; declare the variable to become the array

Local $oIE = _IECreate("http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/",0,0)
Local $links =  _IELinkGetCollection($oIE)

    For $link In $links

        If StringInStr($link.href,"http://graydanielsnissanofjackson.com/Jackson-MS/For-Sale/New/?Model=") Then
            ConsoleWrite("Link Found: " & $Link.href & @CRLF)
            
            If IsArray($aLinks) Then
                ReDim $aLinks[ubound($aLinks)+1]
            Else
                Local $aLinks[1]
            EndIf
            $aLinks[ubound($aLinks)-1] = $link.href     ; add the link to your array
        EndIf
    Next
_ArrayDisplay($aLinks)
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

With most of the scripts I've written, I've really never had to build an array from scratch. I've always had the data for the most part and it was a matter of declaring, sorting or deleting data in the array or telling the script the specified data in the array I needed. I never really had to build the arrays like this. This will help with my other scripts because I write a ton of data into Excel and I'm currently doing it line by line. It will be sooooo much faster to actually insert the array into an Excel worksheet. Thank you guys sooooo much for your help.

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