0

I've been using a code I've made for scraping some data from some sites, now that I tried to add a new site to the list I get this error: Object doesnt support this property or method. Can I use the exact same code as others but this time I get this message, does anyone know why? The error message appears when I try to get the 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
2
  • have you debug stepped through the code? Commented Sep 12, 2013 at 11:46
  • Yes, I ran line to line and this is the part I get an error, I tried Pradeep's sugestion, changed it to GetElementsByTagName, but I don't get any elements Commented Sep 12, 2013 at 13:35

1 Answer 1

4

There is no method as getelementsbyclassname in Internet Explorer/WebBrowser control.

I am assuming you wanted to use GetElementsByTagName instead, which gets all the elements with specified tag name.

EDIT :

Updated code sample:

With IE
    For Each ele In .document.GetElementsByTagName("td")
        If ele.classname = "place" Then
            cont = cont + 1
        End If
    Next ele
End With
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I'm not a VBA and I know nothing about creating websites, but I used this code to get infos from others two websites. How would you count the number of times this tag (PLACE) appears in the source code? <td class="place" style="width:10%; text-align:center;"><span>Aberta</span></td>
Holy Diddly-Ho! It worked perfectly! Your answer just gave me a reason to re-check all my codes and try to make it better and understandable!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.