Linked Questions

Popular Questions

Using getElementById VBA webscraping

Asked by At

The following macro works fine in extracting data from webpages in a range using getElementsByClassName but I need it changed to getElementsById since the class name is not unique. Any help here will be appreciated

Dim oHtml As HTMLDocument
Dim oElement As Object
Dim url As String
Set oHtml = New HTMLDocument

Application.ScreenUpdating = False

Sheets("ASIN").Range("A1:A100").ClearContents

url = Sheets("ASIN").Range("L2").Value


With CreateObject("MSXML2.XMLHTTP")
.Open "GET", url, False
.send
oHtml.body.innerHTML = .responseText
End With


Set oElement = oHtml.getElementsByClassName("a-color-price")
For i = 0 To oElement.Length - 1
 Sheets("ASIN").Range("A" & (i + 1)) = oElement(i).innerText
Next i
Application.ScreenUpdating = True

Any help to use getElementById will be appreciated.

Webpage inspection screenshot attached

enter image description here

Related Questions