Scrape game data van website

Er zijn veel mogelijkheden om gegevens van een website te halen (ook wel webscraping genoemd). Dit is een van de voorbeelden.

Sub ScrapeGameData()
'set reference to the Microsoft HTML Object Library
    Dim ie As Object ' Internet Explorer instance
    Dim doc As Object ' HTML Document
    Dim platformLinks As Object, titles As Object, prices As Object
    Dim i As Integer
    
    ' Create a new Internet Explorer instance
    Set ie = CreateObject("InternetExplorer.Application")
    
    ' Navigate to the webpage
    ie.Visible = False
    ie.navigate "https://www.gameshop.nl/webshop/index.php" ' Change to the correct URL
    
    ' Wait for the page to load
    Do While ie.Busy Or ie.readyState <> 4
        DoEvents
    Loop
    
    ' Get the document
    Set doc = ie.document
    
    ' Get elements by class name
    Set platformLinks = doc.getElementsByClassName("platform-link")
    Set titles = doc.getElementsByClassName("titel")
    Set prices = doc.getElementsByClassName("prijs")
    
    ' Output results to Immediate Window (Ctrl+G in VBA editor to view)
    For i = 0 To platformLinks.Length - 1
        Debug.Print "Platform: " & platformLinks.Item(i).innerText
        Debug.Print "Title: " & titles.Item(i).innerText
        Debug.Print "Price: " & prices.Item(i).innerText
        Debug.Print "----------------------------"
    Next i

    ' Clean up
    ie.Quit
    Set ie = Nothing
    Set doc = Nothing
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *