【问题标题】:Capture all the data捕获所有数据
【发布时间】:2019-12-13 11:30:37
【问题描述】:

我有一个关于 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

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

【问题讨论】:

    标签: excel vba web-scraping html-parsing


    【解决方案1】:

    您的意思是要从网站的下一页获取文本? 您可以按照您的方式继续,但只需遍历页码:

    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
    

    【讨论】:

      猜你喜欢
      • 2015-01-14
      • 2015-09-28
      • 2021-07-18
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      相关资源
      最近更新 更多