2015-10-27 91 views
0

我需要遍歷一個對象的元素(如調試器所指出的)爲DispHTMLElementCollection訪問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 
+0

更容易,如果你可以發佈你正在使用的代碼,並展示你如何獲得這個集合。 –

+0

我在該頁面上看不到任何表格。 –

+0

嘗試使用隨機條件進行搜索,以便顯示結果,並創建表格... – drec4s

回答

0

使用從蒂姆·威廉姆斯

反饋
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 

感謝

+0

謝謝你的回答! – drec4s

+0

不客氣,但所有功勞都歸功於Tim Williams的Html DOM知識。 –