捕获所有数据

Capture all the data

我有一个关于 HTML 解析的问题。我想将 this site 中的文本捕获到我当前的电子表格中,但代码只能循环遍历每一页。

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

如何在流程中循环下一页以捕获所有数据?

您是说要从网站的下一页获取文本吗? 您可以按照您的方式继续,但只需循环浏览页码:

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