getElementsByTagName() question

conception_native_0123

Well-known member
Local time
Today, 05:43
Joined
Mar 13, 2021
Messages
1,923
I am scraping a web page and I'm missing a method. can someone help me out? this page spells it out but VBA puts a semicolon in the code when I try it:


the code I have is:
Code:
Dim ie As InternetExplorer, counter As Long, length As Long
Set ie = New InternetExplorer

ie.Visible = True
ie.navigate "https://www.fairhopeartsandcraftsfestival.com/artists/jewelry"

    While ie.Busy
        DoEvents
    Wend

        length = ie.Document.getElementsByTagName("a").length
        counter = ie.Document.getElementsByTagName("a").length
            Debug.Print ie.Document.getElementsByTagName("a")[0].innerHTML
but the code's last line is read by VBA like this:
Code:
Debug.Print ie.Document.getElementsByTagName("a"); [0].innerHTML
can someone give me a push here? I'm not ready to transition to the chromium model yet. thanks.
 
I believe the correct syntax for what you are doing is to place the 0 in () rather than []. According to the documentation for subroutine getElementsByTagName, your return value is an array of elements, and VBA's syntax to index an array is ( n ), not [n].

EDIT: And somehow, the "thumbs down" emoji is left-parenthesis, 0, right-parenthesis. Which was NOT what I intended.

With that square bracketing, I've got NO idea as to what Access thinks that [0] is, but it knows it doesn't belong to the array. To say that it reads the line as though the semicolon is there is to say that the parser does not see the [0] as a legal part of the complex reference - so it breaks at that point. Then, of course, I have no clue why it didn't break with a compile error there either, unless there IS an object named [0] somewhere in scope.
 
Last edited:
thanks doc.. this works just fine:

Code:
Debug.Print ie.Document.getElementsByTagName("a")(0)

not sure why I didn't try it to begin with. :/
 

Users who are viewing this thread

Back
Top Bottom