VBA编码在单个网页上刮取具有相同HTML结构的所有元素

时间:2017-07-31 14:11:17

标签: html vba excel-vba web-scraping excel

我当前的代码可以完美地从网页上的特定元素中“删除”所需的文本:

Sub Test1()
    Dim URL As String
    Dim ieDoc As Object
    Dim cel As Range

    For Each cel In Range("A1", Range("A" & Rows.Count).End(xlUp))
        URL = cel.Value
        With CreateObject("InternetExplorer.Application")
            .Visible = False
            .Navigate URL

            Do Until .ReadyState = 4: DoEvents: Loop

            Set ieDoc = .Document
            cel.Offset(, 1).Value = ieDoc.getElementsByClassName("fsl fwb fcb")(0).getElementsByTagName("a")(0).innerText
           .Quit
        End With
    Next cel    
End Sub

如何修改我的代码以运行具有相同HTML结构的页面上的所有元素?

0 个答案:

没有答案