Scrape data after 2 different buttons clicks

I’m pretty new to web scraping, so please accept my apologies if the question might sound stupid.
I’m trying to scrape the href of each model from this webpage: https://www.aprilia.com/en_EN/index.
The html showing the href data can be seen only after clicking on 2 buttons (the one on the top right corner and the one on the left called "Models"), one after the other.
This is the code I’ve written so far:

Sub get_info()
  
  Dim ie As Object
  Dim address, str_chk As String
  Dim my_data As Object
  Dim oHTML_Element As IHTMLElement
  Dim i As Long
  
  address = "https://www.aprilia.com/en_EN/index"

  Set ie = CreateObject("InternetExplorer.Application")
  ie.navigate address 'the one mentioned above
  ie.Visible = False
  
   Do While ie.Busy Or ie.readyState <> 4
    DoEvents
    Loop
  
    For Each oHTML_Element In ie.document.getElementsByName("button")
    If oHTML_Element.className = "header__menu-services__nav button button--icon" Then
        oHTML_Element.Click
    End If
    Next
  
    Application.Wait Now + #12:00:05 AM#
    
    For Each oHTML_Element In ie.document.getElementsByName("Models")
        oHTML_Element.Click
    Next
    
    Application.Wait Now + #12:00:05 AM#
    
  ==>  Set my_data = html.getElementsByClassName("card-product card-product--family")
    For Each elem In my_data
    
        For i = 0 To elem.getElementsByTagName("a").Length - 1
                
        str_chk = elem.getElementsByTagName("a")(i).href
        
        ws.Cells(9 + j, 7).Value = str_chk
        j = j + 1
            
        Next i

    Next elem

    ie.Quit
    Set ie = Nothing
    End Sub

after launching the script, i got Error ‘424’ – Object Required, aiming at the row where i set my_data (see above code).
I guess that means that I’m not able to properly click on the two buttons and that, as consequence, html code is not available.
Could you please provide any suggestion how to solve this problem? Any help is highly appreciated.

110 thoughts on “Scrape data after 2 different buttons clicks”

Leave a Comment