Moderatori: Anthony47, Flash30005
' >>> RIGOROSAMENTE IN TESTA A UN MODULO STANDARD DEL VBA <<<
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub GetWebTables()
Dim IE As Object, IESh As Worksheet, FlEx As Boolean, myTim As Single
Dim I As Long, KK As Long, aColl As Object, myUrl As String, OCLen As Long
Dim myItm As Object, tRtR As Object, TdTd As Object, J As Long
'ATTENZIONE, il foglio che specifichi verra' azzerato all'avvio della macro
Set IESh = Sheets("ImportedTables") '<<< Il fpglio da usare per l'importazione
myUrl = "https://mercati.ilsole24ore.com/obbligazioni/titoli-di-stato/btp/3" '<<< La pagina
'
If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True '...
.navigate myUrl '...
Sleep 100
Do While .Busy: DoEvents: Sleep (20): Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents: Sleep (20): Loop 'Attesa document
End With
'
I = 0: KK = 1
IESh.Range("A:Z").ClearContents
IESh.Range("A:Z").NumberFormat = "@" '<<< Importa tutte le colonne in formato Testo
myTim = Timer
'Wait for all Tables to assemple
Do
Set aColl = IE.document.getElementsByTagName("TABLE")
If aColl.Length > OCLen Then
OCLen = aColl.Length
FlEx = False
myTim = Timer
Else
If FlEx And aColl.Length > 0 Then Exit Do 'Tables stable
FlEx = True
End If
Debug.Print aColl.Length, Timer - myTim
If Timer > (myTim + 5) Or Timer < myTim Then Exit Do 'or Timeout
Sleep 500
DoEvents
Loop
For Each myItm In aColl
' If ... Then 'Riserva...
IESh.Cells(I + 1, "A").Value = "TABLE#_" & KK: KK = KK + 1: I = I + 1
For Each tRtR In myItm.Rows
For Each TdTd In tRtR.Cells
IESh.Cells(I + 1, J + 1) = TdTd.innerText
J = J + 1
Next TdTd
I = I + 1: J = 0
Next tRtR
' End If
I = I + 1
Next myItm
'
On Error Resume Next
IE.Quit
Set IE = Nothing
MsgBox ("Tabelle importate: " & KK - 1)
End Sub
Torna a Applicazioni Office Windows
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
Perchè l'importazione dati con Selenium non fuziona? Autore: aggittoriu |
Forum: Applicazioni Office Windows Risposte: 7 |
copia di dati da un file chiuso e elaborazione Autore: luca62 |
Forum: Applicazioni Office Windows Risposte: 2 |
Visitano il forum: Nessuno e 46 ospiti