You need to reference Microsoft HTML Object Library & Microsoft XML, 3.0
You didn't mention what value you wanted to grab; this just loops the known HTML of the web page and fills a MSFlexGrid control.
Code:
Private Sub Command1_Click()
Dim HTTPRequest As MSXML2.XMLHTTP
Dim url As String
Dim htmlDoc As HTMLDocument
Dim tbl As HTMLTable
Dim tblRow As HTMLTableRow
Dim tblCol As HTMLTableCol
Dim rowNum As Integer
Dim colNum As Integer
Dim innerColNum As Integer
Dim grdDataColValue As String
Set HTTPRequest = New MSXML2.XMLHTTP
Set htmlDoc = New HTMLDocument
' Open the HTTP request and send it
url = "http://www.lottoconsult.it/estrazioni_lotto.asp?anno=2025"
HTTPRequest.Open "GET", url, False
HTTPRequest.send
htmlDoc.body.innerHTML = HTTPRequest.responseText
' extract the table
innerColNum = 1
Set tbl = htmlDoc.getElementsByTagName("table")(7) ' examine the page source to see which table holds the data to get as it doesn't have an id
If Not tbl Is Nothing Then
' find all the table rows
For Each tblRow In tbl.getElementsByTagName("tr")
If rowNum = 0 Then
' count the columns needed for the grid - first header row
' this site doesn't use "th" for the table header
' count the column headers
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
colNum = colNum + 1
Next tblCol
' set the number of columns
grdData.cols = colNum
' write the column headers
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
grdData.TextMatrix(0, colNum) = tblCol.innerText
grdData.ColWidth(colNum) = 1250
colNum = colNum + 1
Next tblCol
ElseIf rowNum = 1 Then
' second header row
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
If colNum < 2 Then
' second row of headers - column 1 & 2 are in the first column of row 1
grdDataColValue = grdDataColValue & tblCol.children(0).innerText & " "
colNum = colNum + 1
Else
If colNum = 2 Then
' write the first 2 cols to col 1 of the grid
grdData.TextMatrix(rowNum, 0) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
grdDataColValue = grdDataColValue & tblCol.innerText & " "
innerColNum = innerColNum + 1
If innerColNum = 6 Then
' once the 5 numbers are found for the column, write it to the grid, clear the var
' reset the inner column count and move to the next column
grdData.TextMatrix(rowNum, colNum - 2) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
End If
Next tblCol
Else
' add the row of data to the grid
grdData.rows = grdData.rows + 1
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
If colNum < 2 Then
' second row of headers - column 1 & 2 are in the first column of row 1
grdDataColValue = grdDataColValue & tblCol.children(0).innerText & " "
colNum = colNum + 1
Else
If colNum = 2 Then
' write the first 2 cols to col 1 of the grid
grdData.TextMatrix(rowNum, 0) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
' all other rows have 5 numbers per column
grdDataColValue = grdDataColValue & tblCol.innerText & " "
innerColNum = innerColNum + 1
If innerColNum = 6 Then
' once the 5 numbers are found, write it to the grid, clear the var
' reset the inner column count and move to the next column
grdData.TextMatrix(rowNum, colNum - 2) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
End If
Next tblCol
End If
rowNum = rowNum + 1
DoEvents
Next tblRow
End If
' release the objects
Set HTTPRequest = Nothing
Set htmlDoc = Nothing
lblStatus.Caption = "Extracted " & CStr(grdData.rows) & " rows from table": DoEvents
End Sub
you need to reference microsoft html object library & microsoft xml, 3.0
you didn't mention what value you wanted to grab; this just loops the known html of the web page and fills a msflexgrid control.
Code:
private sub command1_click()
dim httprequest as msxml2.xmlhttp
dim url as string
dim htmldoc as htmldocument
dim tbl as htmltable
dim tblrow as htmltablerow
dim tblcol as htmltablecol
dim rownum as integer
dim colnum as integer
dim innercolnum as integer
dim grddatacolvalue as string
set httprequest = new msxml2.xmlhttp
set htmldoc = new htmldocument
' open the http request and send it
url = "http://www.lottoconsult.it/estrazioni_lotto.asp?anno=2025"
httprequest.open "get", url, false
httprequest.send
htmldoc.body.innerhtml = httprequest.responsetext
' extract the table
innercolnum = 1
set tbl = htmldoc.getelementsbytagname("table")(7) ' examine the page source to see which table holds the data to get as it doesn't have an id
if not tbl is nothing then
' find all the table rows
for each tblrow in tbl.getelementsbytagname("tr")
if rownum = 0 then
' count the columns needed for the grid - first header row
' this site doesn't use "th" for the table header
' count the column headers
colnum = 0
for each tblcol in tblrow.getelementsbytagname("td")
colnum = colnum + 1
next tblcol
' set the number of columns
grddata.cols = colnum
' write the column headers
colnum = 0
for each tblcol in tblrow.getelementsbytagname("td")
grddata.textmatrix(0, colnum) = tblcol.innertext
grddata.colwidth(colnum) = 1250
colnum = colnum + 1
next tblcol
elseif rownum = 1 then
' second header row
colnum = 0
for each tblcol in tblrow.getelementsbytagname("td")
if colnum < 2 then
' second row of headers - column 1 & 2 are in the first column of row 1
grddatacolvalue = grddatacolvalue & tblcol.children(0).innertext & " "
colnum = colnum + 1
else
if colnum = 2 then
' write the first 2 cols to col 1 of the grid
grddata.textmatrix(rownum, 0) = grddatacolvalue
grddatacolvalue = ""
innercolnum = 1
colnum = colnum + 1
end if
grddatacolvalue = grddatacolvalue & tblcol.innertext & " "
innercolnum = innercolnum + 1
if innercolnum = 6 then
' once the 5 numbers are found for the column, write it to the grid, clear the var
' reset the inner column count and move to the next column
grddata.textmatrix(rownum, colnum - 2) = grddatacolvalue
grddatacolvalue = ""
innercolnum = 1
colnum = colnum + 1
end if
end if
next tblcol
else
' add the row of data to the grid
grddata.rows = grddata.rows + 1
colnum = 0
for each tblcol in tblrow.getelementsbytagname("td")
if colnum < 2 then
' second row of headers - column 1 & 2 are in the first column of row 1
grddatacolvalue = grddatacolvalue & tblcol.children(0).innertext & " "
colnum = colnum + 1
else
if colnum = 2 then
' write the first 2 cols to col 1 of the grid
grddata.textmatrix(rownum, 0) = grddatacolvalue
grddatacolvalue = ""
innercolnum = 1
colnum = colnum + 1
end if
' all other rows have 5 numbers per column
grddatacolvalue = grddatacolvalue & tblcol.innertext & " "
innercolnum = innercolnum + 1
if innercolnum = 6 then
' once the 5 numbers are found, write it to the grid, clear the var
' reset the inner column count and move to the next column
grddata.textmatrix(rownum, colnum - 2) = grddatacolvalue
grddatacolvalue = ""
innercolnum = 1
colnum = colnum + 1
end if
end if
next tblcol
end if
rownum = rownum + 1
doevents
next tblrow
end if
' release the objects
set httprequest = nothing
set htmldoc = nothing
lblstatus.caption = "extracted " & cstr(grddata.rows) & " rows from table": Doevents
end sub
You need to reference Microsoft HTML Object Library & Microsoft XML, 3.0
You didn't mention what value you wanted to grab; this just loops the known HTML of the web page and fills a MSFlexGrid control.
Code:
Private Sub Command1_Click()
Dim HTTPRequest As MSXML2.XMLHTTP
Dim url As String
Dim htmlDoc As HTMLDocument
Dim tbl As HTMLTable
Dim tblRow As HTMLTableRow
Dim tblCol As HTMLTableCol
Dim rowNum As Integer
Dim colNum As Integer
Dim innerColNum As Integer
Dim grdDataColValue As String
Set HTTPRequest = New MSXML2.XMLHTTP
Set htmlDoc = New HTMLDocument
' Open the HTTP request and send it
url = "http://www.lottoconsult.it/estrazioni_lotto.asp?anno=2025"
HTTPRequest.Open "GET", url, False
HTTPRequest.send
htmlDoc.body.innerHTML = HTTPRequest.responseText
' extract the table
innerColNum = 1
Set tbl = htmlDoc.getElementsByTagName("table")(7) ' examine the page source to see which table holds the data to get as it doesn't have an id
If Not tbl Is Nothing Then
' find all the table rows
For Each tblRow In tbl.getElementsByTagName("tr")
If rowNum = 0 Then
' count the columns needed for the grid - first header row
' this site doesn't use "th" for the table header
' count the column headers
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
colNum = colNum + 1
Next tblCol
' set the number of columns
grdData.cols = colNum
' write the column headers
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
grdData.TextMatrix(0, colNum) = tblCol.innerText
grdData.ColWidth(colNum) = 1250
colNum = colNum + 1
Next tblCol
ElseIf rowNum = 1 Then
' second header row
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
If colNum < 2 Then
' second row of headers - column 1 & 2 are in the first column of row 1
grdDataColValue = grdDataColValue & tblCol.children(0).innerText & " "
colNum = colNum + 1
Else
If colNum = 2 Then
' write the first 2 cols to col 1 of the grid
grdData.TextMatrix(rowNum, 0) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
grdDataColValue = grdDataColValue & tblCol.innerText & " "
innerColNum = innerColNum + 1
If innerColNum = 6 Then
' once the 5 numbers are found for the column, write it to the grid, clear the var
' reset the inner column count and move to the next column
grdData.TextMatrix(rowNum, colNum - 2) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
End If
Next tblCol
Else
' add the row of data to the grid
grdData.rows = grdData.rows + 1
colNum = 0
For Each tblCol In tblRow.getElementsByTagName("td")
If colNum < 2 Then
' second row of headers - column 1 & 2 are in the first column of row 1
grdDataColValue = grdDataColValue & tblCol.children(0).innerText & " "
colNum = colNum + 1
Else
If colNum = 2 Then
' write the first 2 cols to col 1 of the grid
grdData.TextMatrix(rowNum, 0) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
' all other rows have 5 numbers per column
grdDataColValue = grdDataColValue & tblCol.innerText & " "
innerColNum = innerColNum + 1
If innerColNum = 6 Then
' once the 5 numbers are found, write it to the grid, clear the var
' reset the inner column count and move to the next column
grdData.TextMatrix(rowNum, colNum - 2) = grdDataColValue
grdDataColValue = ""
innerColNum = 1
colNum = colNum + 1
End If
End If
Next tblCol
End If
rowNum = rowNum + 1
DoEvents
Next tblRow
End If
' release the objects
Set HTTPRequest = Nothing
Set htmlDoc = Nothing
lblStatus.Caption = "Extracted " & CStr(grdData.rows) & " rows from table": DoEvents
End Sub
hi bro...
your code dont work now!
Peraphs the site is changed?
Table 7 not exists now!
You'll need to inspect the page / view the page source to see (count them) which <table> the data is in now or see if it has a unique id and use that instead.