La situazione è questa : vorrei scaricare una serie di tabelle che ho aperto con Selenium su chrome , dopo opportuni settaggi ottengo un elenco suddiviso in diverse tabelle , circa 20 . Ho provato con questa sotto ma non salva tutte le tabelle. Quindi ho pensato alla macro di Anthony di qualche anno fa , ma come inserirla nella macro primaria ?
- Codice: Seleziona tutto
'scarica tutte le pagine
For i = 1 To 14 'n. pagine
Set Table = Dd.FindElementByCss("#tableResults")
For Each row In Table.FindElementsByTag("tr")
c = 1
For Each cell In row.FindElementsByTag("td")
Cells(r, c).Value = cell.Text
c = c + 1
Next cell
r = r + 1
Next row
next i
]
Option Explicit
Dim WPage As Object
Sub PrintTables()
Dim myIsin As String, myUrl As String
'
'Crea Driver:
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.ChromeDriver")
End If
Sheets("Dividendi").Select
Range("A:M").ClearContents
'
myIsin = "KO"
myUrl = "https://it.investing.com/dividends-calendar/"
'
'Prima pagina:
WPage.Start "Chrome"
Call GetAllTablesArr(myUrl) 'Posiziona in colonna A
'
'Quit Selenium
WPage.Quit
Set WPage = Nothing
MsgBox ("Informazioni raccolte...")
End Sub
Sub GetAllTablesArr(myUrl As String, Optional rNum0 As Long = 1, Optional cNum0 As Long = 1)
Dim TBColl As Object
Dim I As Long, J As Long, myTim As Single
Dim RNum As Long, CNum As Long
Dim TArr
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.ChromeDriver")
End If
WPage.Get myUrl
'
myTim = Timer
'
Set TBColl = WPage.FindElementsByTag("table")
RNum = rNum0: CNum = cNum0
'
For I = 1 To TBColl.Count 'Scan delle Tabelle presenti
TArr = TBColl(I).AsTable.Data
RNum = RNum + 1
Cells(RNum, CNum).Value = "## Table " & I
If (UBound(TArr) * UBound(TArr, 2)) > 0 Then
Cells(RNum + 1, CNum).Resize(UBound(TArr), UBound(TArr, 2)).Value = TArr
End If
RNum = RNum + UBound(TArr) + 1
DoEvents
Next I
Debug.Print "FINE", RNum, Format(Timer - myTim, "0.00"), myUrl
End Sub