1

I am trying to extract the team names but i get the "Run time error 424 Object required" on this line

Set lists = html.getElementsByClassName("KambiBC-event-item__participants-container") 

, if anyone could point me in the right direction it would be nice.

    Sub useClassnames()
    Dim lists As IHTMLElementCollection
    Dim anchorElements As IHTMLElementCollection
    Dim ulElement As HTMLUListElement
    Dim liElement As HTMLLIElement
    Dim row As Long
    Dim ie As InternetExplorer

       Set ie = New InternetExplorer

           With ie.navigate "https://www.unibet.ro/betting#filter/all/all/all/all/in-play"
           .Visible = True
      Do While ie.readyState <> READYSTATE_COMPLETE
      DoEvents
      Loop
      End With

      Set lists = html.getElementsByClassName("KambiBC-event-item__participants-container")

row = 1

     For Each ulElement In lists

       For Each liElement In ulElement.getElementsByClassName("KambiBC-event-participants")

       Set anchorElements = liElement.getElementsByClassName("KambiBC-event-participants__name")

          If anchorElements.Length > 0 Then
           Cells(row, 1) = anchorElements.Item(0).innerText
           row = row + 1
         End If
     Next liElement
     Next ulElement

   End Sub

1 Answer 1

0

Error 424 is an Object Required Error. What is Html in Set lists = html.getElementsByClassName("KambiBC-event-item__participants-container")?

What you need is

Set lists = ie.document.getElementsByClassName("KambiBC-event-item__participants-container")

Code that I used

Sub useClassnames()
    Dim lists As IHTMLElementCollection
    Dim anchorElements As IHTMLElementCollection
    Dim ulElement As HTMLUListElement
    Dim liElement As HTMLLIElement
    Dim row As Long
    Dim ie As InternetExplorer

    Set ie = New InternetExplorer

    With ie
        .navigate "https://www.unibet.ro/betting#filter/all/all/all/all/in-play"
        .Visible = True

        Do While ie.readyState <> READYSTATE_COMPLETE
            DoEvents
        Loop
    End With

    Set lists = ie.document.getElementsByClassName("KambiBC-event-item__participants-container")

    row = 1

    For Each ulElement In lists
        For Each liElement In ulElement.getElementsByClassName("KambiBC-event-participants")
            Set anchorElements = liElement.getElementsByClassName("KambiBC-event-participants__name")

            If anchorElements.Length > 0 Then
                Cells(row, 1) = anchorElements.Item(0).innerText
                row = row + 1
            End If
        Next liElement
    Next ulElement
End Sub

Screenshot

enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

I was trying to adapt the response from this thread <stackoverflow.com/questions/41851152/…> that seems to work to my needs. It gives me the same error .
I just tried your above code which is posted in the question and it works for me :)
yes :) I just replaced Html with ie.document in the code and it works for me
Interesant as it gave me the same error. Can you tell me what references have you used?
1 Microsoft Internet Control 2 Microsoft HTML Object Library
|

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.