Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

Select attribute value via VBA & XMLHttpRequest

$
0
0

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"
        .send
        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


Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>