(Solved) – Select attribute value via VBA & XMLHttpRequest

  • by

My question is related to other question VBA – Select HTML item using VBA. How can select and click data-id attribute value by using an XMLHttpRequest without Internet Explorer?
So far my code looks like this:

Sub Data_multi()
    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim topic As HTMLHtmlElement
    Dim i As Integer
    For i = 1 To 4 'last page
    Application.ScreenUpdating = False
    With http
        .Open "GET", "https://www.castorama.ru/building-materials/building-dry-materials-and-primers?limit=96&p=" & i, False
        .setRequestHeader "User-Agent", "Mozilla/5.0"
        .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
        Do: DoEvents: Loop Until .readyState = 4
        html.body.innerHTML = .responseText
    End With

    For Each topic In html.getElementsByClassName("product-info")
        With topic.getElementsByClassName("product-name")
            If .Length Then x = x   1: Cells(x, 1) = .item(0).innerText
        End With
        With topic.getElementsByClassName("price")
            If .Length Then Cells(x, 2) = .item(0).innerText
        End With
    Next topic
  Next i
 Application.ScreenUpdating = True
End Sub

Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *