Getelementsbyclassname返回错误

时间:2013-09-12 11:38:38

标签: vba

我一直在使用我从一些网站上抓取一些数据的代码,现在我试图在列表中添加一个新网站我得到了这个错误:对象不支持这个属性或方法。 我可以使用与其他人完全相同的代码,但这次我收到此消息,有人知道为什么吗? 当我尝试获取elementbyclassname时会出现错误消息。

Sub Zelo()
    Dim dia As String
    Dim mes As String
    Dim ano As String

    dia = "14"
    mes = "09"
    ano = "13"

    Dim cont As Integer
    Dim i As Integer
    Dim URL As String
    Dim IE As Object
    IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    URL = "http://www2.zelo.com.br/weddingListSearch.aspx?dsName=&dsLocation=&dtWedding=" & dia & "/" & mes & "/" & ano & "&idproduct=&qty="

    IE.Navigate(URL)

    Do
        DoEvents()
    Loop Until IE.READYSTATE = 4

    cont = 0

    With IE
        For Each ele In .document.getelementsbyclassname("name") ' Here I have the error message
            If ele.classname = "place" Then
                cont = cont + 1
            End If
        Next ele
    End With

    Sheets("Plan2").Range("A2") = cont

    IE.Quit()
End Sub

1 个答案:

答案 0 :(得分:4)

Internet Explorer / WebBrowser控件中没有getelementsbyclassname的方法。

我假设您想要使用GetElementsByTagName,而是获取具有指定标记名称的所有元素。

编辑:

更新了代码示例:

With IE
    For Each ele In .document.GetElementsByTagName("td")
        If ele.classname = "place" Then
            cont = cont + 1
        End If
    Next ele
End With