Lottery results Belgium

jacafate

New Member
Joined
Mar 3, 2024
Messages
2
Platform
  1. Windows
Hi,
Im creating an excel sheet to calculate the profit of the lottery.
I want to import the winning numbers and the prize breakdown into my excel automatically.

The website is located here : Lotto uitslagen - zaterdag 02 maart 2024 - Nationale Loterij
This is the info I need in my Excel
2024-03-03_14h22_43.jpg



I already tried to create a macro with a save mhtml file. Here is the code.

But it don't find the numbers in this file.

Perhaps someone has another solution to accomplish this ?

Sub ExtractULDataToExcel()
Dim xmlHTTP As Object
Dim htmlDoc As Object
Dim ulElements As Object
Dim ulElement As Object
Dim liElements As Object
Dim liElement As Object
Dim rowIndex As Integer

' Create a new instance of MSXML2.ServerXMLHTTP
Set xmlHTTP = CreateObject("MSXML2.ServerXMLHTTP")

' Define the URL of the webpage containing the HTML content
xmlHTTP.Open "GET", "Lotto uitslagen - woensdag 28 februari 2024 - Nationale Loterij", False
xmlHTTP.send

' Wait for the webpage to load
Do While xmlHTTP.readyState <> 4 ' 4 means complete
Application.Wait Now + TimeValue("0:00:05") ' Wait for 5 seconds
Loop

' Save the webpage as MHTML file
Dim fileNumber As Integer
fileNumber = FreeFile
Open "c:\temp\webpage.mhtml" For Output As #fileNumber
Print #fileNumber, xmlHTTP.responseText
Close #fileNumber

' Create a new instance of Internet Explorer
Set htmlDoc = CreateObject("htmlfile")
htmlDoc.body.innerHTML = xmlHTTP.responseText

' Load the saved MHTML file
htmlDoc.Open "webpage.mhtml"

' Get all <ul> elements with the specified class
Set ulElements = htmlDoc.getElementsByTagName("ul")

' Initialize row index for Excel
rowIndex = 1

' Loop through each <ul> element
For Each ulElement In ulElements
' Check if the <ul> element has the desired class
If ulElement.className = "lnl-draw-numbers " Then
' Get all <li> elements within the <ul> element with the desired class
Set liElements = ulElement.getElementsByClassName("lnl-draw-numbers__winning-number")

' Loop through each <li> element and extract its text
For Each liElement In liElements
' Output text to Excel
ThisWorkbook.Sheets("Sheet1").Cells(rowIndex, 1).Value = liElement.innerText
rowIndex = rowIndex + 1
Next liElement
End If
Next ulElement

' Clean up
Set xmlHTTP = Nothing
Set htmlDoc = Nothing
End Sub

Any help would be thankfull

Kind Regards,
Jacafate
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
A simpler means would be with Power Query aka Get and Transform Data and found on the Data Tab of the Ribbon.
Data-->Get and Transform Data-->From Web
Enter the URL
PQ will go to the web site and give you a choice of which table to select.

 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top