How to get the data from the children of a specific parent HTML element in VBA
<p>Once again I find myself encountering a very specific problem. I'm pretty new to VBA, and especially HTML, so bear with me. I've built a functioning web scraper in VBA, but there are a few specific tasks I want to accomplish that I can't figure out. </p>

<p><a href="https://gist.github.com/LiterallyThis/4d5a1d755ed2a67541fb169a8422c714" rel="nofollow">Here is the HTML sample that my question refers to.</a></p>

<p>I've replaced all the stuff that doesn't matter with ellipses. The important part that I want to scrape is in the "a" tags, the "data-shorturl" (or just the <code>innerText</code>). This is a website name. There are up to five of these, but there are not always five. This is also just one of two section with up to five websites listed. The posted section has the children of <code>&lt;div class="referralsSites referring"&gt;</code>, and the other has the children of <code>&lt;div class="referralsSites destination"&gt;</code>. </p>

<p>Each website in the "referring" section I want to assign to "Up" variables -- the first website assigned to "Up1", the second to "Up2", and so on, but only depending on how many websites are in the "referring" section. I want to do the same in the "destination" section, but assigned to "Down" variables (Down1, Down2, etc.) depending on how many destination sites there are.</p>

<p>If I were to just use <code>getElementsByClassName("websitePage-listItemLink js-tooltipTarget")</code>, for example, I wouldn't be able to differentiate between the referral and destination sites.</p>

<p>Here is my code so far:</p>

<pre><code>Sub GetSimilarWebData()
    Dim appIE As InternetExplorer
    Dim HTML As HTMLDocument
    Dim ieWindow As SHDocVw.InternetExplorer
    Dim URL As String
    Dim Rankings As IHTMLElementCollection, Traffic As IHTMLElementCollection, ReferSites As IHTMLElementCollection, DestSites As IHTMLElementCollection, _
        rSite As IHTMLElement, rSiteNo As Long, dSite As IHTMLElement, dSiteNo As Long, GlobalRank As String, CountryName As String, CountryRank As String, _
        Visits As String, Direct As String, Refer As String, Search As String, Social As String, Display As String, _
        Up1 As String, Up2 As String, Up3 As String, Up4 As String, Up5 As String, _
        D1 As String, D2 As String, D3 As String, D4 As String, D5 As String
    Dim FraudLast As Long
    CheckLast = Worksheets("Sheet1").Range("I1").End(xlDown).Offset(1).Row

    webStr = Worksheets("Sheet1").Range("A" &amp; CheckLast).Value

    Set appIE = New InternetExplorer
        appIE.Visible = False
        appIE.navigate "https://www.similarweb.com/website/" &amp; webStr

    Do While appIE.readyState &lt;&gt; READYSTATE_COMPLETE
        Application.StatusBar = "Connecting to SimilarWeb..."
        DoEvents
    Loop

    Set HTML = appIE.document

    Set appIE = Nothing
        Application.StatusBar = ""

    Set Rankings = HTML.getElementsByClassName("rankingItem-value")
        GlobalRank = Rankings(0).innerText
            If GlobalRank = "N/A" Then
                GlobalRank = "null"
                CountryName = "null"
                CountryRank = "null"
            Else
                CountryName = HTML.getElementsByClassName("rankingItem-subTitle")(1).innerText
                CountryRank = Rankings(1).innerText
            End If

    Visits = HTML.getElementsByClassName("engagementInfo-value engagementInfo-value--large u-text-ellipsis")(0).innerText
        If InStr(Visits, "M") &lt;&gt; 0 Then
            Visits = Replace(Visits, ".", "")
            Visits = Replace(Visits, "M", "00000")
        ElseIf InStr(Visits, "K") &lt;&gt; 0 Then
            Visits = Replace(Visits, ".", "")
            Visits = Replace(Visits, "K", "00")
        ElseIf InStr(Visits, "B") &lt;&gt; 0 Then
            Visits = Replace(Visits, ".", "")
            Visits = Replace(Visits, "B", "00000000")
        End If

    Set Traffic = HTML.getElementsByClassName("trafficSourcesChart-value")
        Direct = Traffic(0).innerText
        Refer = Traffic(1).innerText
        Search = Traffic(2).innerText
        Social = Traffic(3).innerText
        Display = Traffic(4).innerText

'Here's what I've started off with:    
    Set ReferSite = HTML.getElementsByClassName("referralsSites referring")
        rSiteNo = ReferSite.Length
    Set DestSite = HTML.getElementsByClassName("referralsSites destination")
        dSiteNo = DestSite.Length
        'For Each rSite In ReferSite
End Sub
</code></pre>

<p>I'm not really sure how to approach the problem. Everything else in my code works fine, but of course if there's anything I can do to improve the speed that would also be welcome.</p>

<p>All of this is referring to data on similarweb.com.</p>