Search code examples
excelvbaweb-scrapinghtml-parsing

Capture all the data


I have a question relating to HTML parsing. I would like to catch text from this site into my current spreadsheet, but code can only loop through each 1 page.

Sub Data()
    Dim Http As New XMLHTTP60, Html As New HTMLDocument, topic As HTMLHtmlElement
    With Http
        .Open "GET", "https://voronezh.leroymerlin.ru/catalogue/dekorativnye-oboi/?sortby=1&display=90", False
        .send
        Html.body.innerHTML = .responseText
    End With
    For Each topic In Html.getElementsByClassName("ui-product-card__info")
        With topic.getElementsByClassName("product-name")
            If .Length Then x = x + 1: Cells(x, 1) = .item(0).innerText
        End With
        With topic.getElementsByClassName("main-value-part")
            If .Length Then Cells(x, 2) = .item(0).innerText
        End With
    Next topic
End Sub

How can I loop the next page in the process to capture all the data?


Solution

  • Do you mean you want to get text from next pages on the website? you can just continue in the way you do, but just loop through the page number:

    Dim i as Integer
    For i = 1 to 96
    
    'Do here the same what you were doing, but replace your website string into:
    
    "https://voronezh.leroymerlin.ru/catalogue/dekorativnye-oboi/? 
    display=90&sortby=1&page=" & i
    
    Next i