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 gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TWO table with the same classname 1

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
221
0
16
IT
i usse this code to get value from a table Italy population history:

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

SQL = "DELETE * FROM TABELLA_ANNI"
CON.Execute (SQL)

With CreateObject("MSXML2.XMLHTTP")
.Open "GET", " False
.send
ODOM.body.innerHTML = .responseText
End With

With ODOM.getElementsByClassName("years")

With .Item(1).getElementsByTagName("tr")

For X = 1 To .Length - 1

ANNO = .Item(X).cells(0).innerText
POPZ = Replace(.Item(X).cells(1).innerText, ",", ".")
PERC = .Item(X).cells(2).innerText

SQL = "INSERT INTO TABELLA_ANNI(ANNO, POPOLAZ, PERC) VALUES ('" & ANNO & "', '" & POPZ & "', '" & PERC & "')"
CON.Execute (SQL)

Next X

End With

End With

End Sub

now i need to get also the value from the table Population projection (2020-2100)
 
You have shown that you know how to INSERT data into a TABELLA_ANNI table, but you do not know how to get the value from the Population projection (2020-2100) table?
How about a SELECT statement?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Is the problem that you don't know how to access the specific table that you want? (and there are more than 2 called 'years' on the page you use)

Perhaps, using your code as a basis, something like

Code:
[COLOR=blue]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

[COLOR=green]'sql = "DELETE * FROM TABELLA_ANNI"
'con.Execute (sql)
[/color]
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", "[URL unfurl="true"]https://countrymeters.info/en/Italy",[/URL] False
    .send
    ODOM.body.innerHTML = .responseText
End With

Dim myHTMLTable As HTMLTable

For Each myHTMLTable In ODOM.getElementsByClassName("years")
    If myHTMLTable.ParentNode.firstElementChild.innerText = "Italy population history" Then
        With myHTMLTable.getElementsByTagName("tr")
        
            For X = 1 To .Length - 1
            
                ANNO = .Item(X).Cells(0).innerText
                POPZ = Replace(.Item(X).Cells(1).innerText, ",", ".")
                PERC = .Item(X).Cells(2).innerText
                
                [COLOR=green]'Sql = "INSERT INTO TABELLA_ANNI(ANNO, POPOLAZ, PERC) VALUES ('" & ANNO & "', '" & POPZ & "', '" & PERC & "')"
                'CON.Execute (Sql)
[/color]            
            Next X
        
        End With
    End If
Next

End Sub
[/color]
 
Or, is the table Population projection (2020-2100) (is that the name of this table?) in your local data base which you connect to by CON connection?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top