Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scraping table dont work 1

sal21

Programmer
Apr 26, 2004
480
IT
Rich (BB code):
Private Sub FILL_TABELLA_ANNI()

Dim ODOM As HTMLDocument
Set ODOM = CreateObject("htmlFile")
Dim X As Long

Dim ANNO As String, POPZ As String, PERC As String

With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", "https://massimilianobenvenuti.it/archivio-storico-estrazioni-del-lotto-new", False
    .send
    ODOM.body.innerHTML = .responseText
End With

Dim myHTMLTable As HTMLTable

For Each myHTMLTable In ODOM.getElementsByClassName("fb-like")
      
        With myHTMLTable.getElementsByTagName("td")
      
            For X = 1 To .Length - 1
          
               debug.print .Item(X).Cells(0).innerText
               debug.print Replace(.Item(X).Cells(1).innerText, ",", ".")
               debug.print .Item(X).Cells(2).innerText

            Next X
      
        End With
Next

End Sub

why this code dont get the value in table!!!

for test you can use also this link with same data:

 
Last edited:
Becasue this code is in not written to scrape the page properly.

here's something to put you on the right tracks, but leaves you with some work to do.

Rich (BB code):
Private Sub FILL_TABELLA_ANNI()
    Dim X As Long
    Dim result As String
    Dim cell As Object
    Dim ODOM As HTMLDocument
    Dim myHTMLTable As HTMLTable
    
    Dim ANNO As String, POPZ As String, PERC As String
    
    Set ODOM = CreateObject("htmlFile")
    
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://massimilianobenvenuti.it/archivio-storico-estrazioni-del-lotto-new", False
        .send
        ODOM.body.innerHTML = .responseText
    End With
    
    Set myHTMLTable = ODOM.getElementsByClassName("cinereousTable")(0)
          
    For Each cell In myHTMLTable.getElementsByTagName("td")
        result = result & cell.innerText & vbTab  ' Use vbNewLine for new rows
    Next cell

End Sub
 
POSSIBLE to use the sintyax:

cell.Rows(1).Cells(2).innerText

to get each value from cells?
 
Last edited:
cell.Rows(1).Cells(2).innerText
Yes but have error .
I think Cell. Not Is the correct object
 
The created `htmlfile` object does not yet have any content yet. So there's no BODY element yet.
After the object is created, initialize it with a blank content like below.

Code:
Set ODOM = CreateObject("htmlFile")
ODOM.open
ODOM.close
 
Given my code should be returning the value of every single cell in the table, what is it that you are actually trying to do? You want to treat the table like an array?

In which case:

result=myHTMLTable.Rows(rowIndex).Cells(colIndex).innertext
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top