访问DispHTMLElementCollection属性

时间:2015-10-27 23:23:49

标签: html xml excel vba excel-vba

我需要遍历一个对象的元素(如调试器所述)是DispHTMLElementCollection

似乎无法访问DispHTMLElementCollection的属性,因为此页面上有一个包含50个td标记的表格,当我打印出此对象的长度时,它会返回0

对此有任何了解。

感谢。

编辑:

使用此代码段,您仍需要破解代码以按搜索按钮以显示一些结果,但在此之后,仍然会返回zero作为长度...

Dim objHTML As HTMLDocument

Set ie = New InternetExplorer
With ie
    .navigate "https://www.oeko-tex.com/en/manufacturers/certified_products/certified_products.html"
    .Visible = True
    While .Busy Or .readyState <> READYSTATE_COMPLETE
       DoEvents
    Wend
    Set objHTML = .document
    DoEvents
End With
Set elementONE = objHTML.getElementsByTagName("td")
Debug.Print TypeName(elementONE)
Debug.Print elementONE.Length

1 个答案:

答案 0 :(得分:0)

使用Tim Williams的反馈

Sub test()

    Dim objHTML As HTMLDocument
    Dim ie As InternetExplorer
    Dim oElemets As Object
    Dim oElement As Object

        Dim h As HTMLOptionElementFactory
    Set ie = New InternetExplorer
    With ie
        .navigate "https://www.oeko-tex.com/en/manufacturers/certified_products/certified_products.html"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
        Set objHTML = .document
        DoEvents
    End With

    ' As per the suggestion Tim Williams proposed
    Set objHTML = objHTML.getElementById("customer-profile")
    Set oElemets = objHTML.getElementsByTagName("td")


    For Each oElement In oElemets
        Debug.Print oElement.nodeName
    Next

End Sub

由于