I'm new here and need some advice for my module. I've created the following Module to scrape data value from alexa.com with specific address: alexa.com/siteinfo/clashofclans.com
The specific value is nested within the following table: https://i.stack.imgur.com/DaPmU.jpg
I try to get data "percent of visitor" from US as the image above with value 9.1%, but the code will only work if United States in first row / first position. https://i.stack.imgur.com/kqpKR.jpg
The below VBA code is my attempt at scraping:
Sub ExtractAlexa()
Dim tickername As String
Dim doc As HTMLDocument
ie.Visible = False
ie.navigate "http://www.alexa.com/siteinfo/clashofclans.com"
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("00:00:4"))
Set doc = ie.document
Set elems = doc.getElementById("demographics_div_country_table").getElementsByTagName("tr")
For Each e In elems
If e.outerHTML Like "*/topsites/countries/US*" Then
Sheet2.Range("E11").Value = Trim(doc.getElementsByTagName("td")(1).innerText)
End If
Next e
ie.Quit
End Sub
Please, does anyone know where I am going wrong here? Thank You.