Per allegare un file:
viewtopic.php?f=26&t=103893&p=605487#p605487
Moderatori: Anthony47, Flash30005
https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/IT0005480980.html?lang=it
https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/XS1768067297.html?lang=it
https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/XS1768074319.html?lang=it
https://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda/USL4441RAA43.html?lang=it
Set TBColl = lDriver.FindElementsByTag("table") 'Esistente
If TBColl.Count > 0 Then I = TBColl.Count Else I = 1 'Aggiunta
ReDim TArr(1 To I) 'Modificata
If Not IsEmpty(AllTabs(1)) Then '<<< IF /END IF Aggiuntivo
For J = 2 To Last1 'Cerca l'intestazione di ogni colonna...
myHead = Cells(1, J).Value
For K = 1 To UBound(AllTabs) '... in tutte le tabelle della pagina...
For L = 1 To UBound(AllTabs(K)) '.... in tutte le righe di ogni tabella
'Se "Trovato" allora scrivi il valore:
If InStr(1, AllTabs(K)(L, 1), myHead, vbTextCompare) = 1 Then
If Cells(I, J) = "" Then Cells(I, J) = AllTabs(K)(L, 2)
End If
Next L
Next K
Next J
End If <<<<<<<<
Option Explicit
Dim WPage As Object
Sub Caller()
'http://www.pc-facile.com/forum/viewtopic.php?f=26&t=112311&p=660077#p660077
Dim myIsin As String, myUrl As String, LastA As Long, I As Long, Last1 As Long
Dim AllTabs, J As Long, K As Long, L As Long, myHead As String, P As Long
Dim S(1 To 2), Z As Integer
'Crea Driver:
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.ChromeDriver")
WPage.Start "Chrome"
WPage.AddArgument ("--headless")
End If
Sheets("dataColl").Select
'
LastA = Cells(Rows.Count, "A").End(xlUp).Row 'Quanti Isin?
Last1 = Cells(1, Columns.Count).End(xlToLeft).Column 'Quante colonne?
'
Range("B2").Resize(LastA + 10, Last1 + 5).ClearContents
Sheets("Isin").Range("j2:N1000").Clear
S(1) = ("AllTables")
S(2) = ("Tlx")
For Z = 1 To 2 ' cerca sui due fogli
For P = 1 To 2 'Cerca su ambedue le pagine web
For I = 2 To LastA ' per ogni Isin
myIsin = Cells(I, 1)
If P = 1 Then
myUrl = "https://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda/" & myIsin & ".html?lang=it"
Else
myUrl = " https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/" & myIsin & ".html?lang=it"
End If
AllTabs = GimmeTablesArr(WPage, myUrl) 'Ottieni la matrice delle tabelle
If Not IsEmpty(AllTabs(1)) Then '<<< IF /END IF Aggiuntivo
For J = 2 To Last1 'Cerca l'intestazione di ogni colonna...
myHead = Cells(1, J).Value
For K = 1 To UBound(AllTabs) '... in tutte le tabelle della pagina...
For L = 1 To UBound(AllTabs(K)) '.... in tutte le righe di ogni tabella
'Se "Trovato" allora scrivi il valore:
If InStr(1, AllTabs(K)(L, 1), myHead, vbTextCompare) = 1 Then
If Cells(I, J) = "" Then Cells(I, J) = AllTabs(K)(L, 2)
End If
Next L
Next K
Next J
End If
Next I
Next S
Next Z
'
'Quit Selenium
WPage.Close
WPage.Quit
'allinea a dx
Range("A" & LastA & Last1).Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
' copia dati su foglio Isin
Range("B2:F" & LastA).Select
With Selection
.Copy
Sheets("Isin").Select
Range("J2").Select
ActiveSheet.Paste
End With
Set WPage = Nothing
MsgBox ("Informazioni raccolte...")
End Sub
Function GimmeTablesArr(lDriver As Object, myUrl As String) As Variant
Dim PColl As WebElements, myItm As Object, TBColl As Object, pCount As Long
Dim I As Long, myTim As Single
Dim TArr()
'
With lDriver
.Get myUrl
myTim = Timer
'
Set TBColl = lDriver.FindElementsByTag("table")
If TBColl.Count > 0 Then I = TBColl.Count Else I = 1 'Aggiunta
ReDim TArr(1 To I)
'
For I = 1 To TBColl.Count
TArr(I) = TBColl(I).AsTable.Data
Next I
GimmeTablesArr = TArr
End With
Debug.Print "GTArr:", "Tables: " & I - 1, Format(Timer - myTim, "0.00"), myUrl
End Function
S(1) = ("AllTables")
S(2) = ("Tlx")
For Z = 1 To 2 ' cerca sui due fogli
'..
'..
Next Z
Ricorda che le tabelle raccolte sul foglio AllTables (e Tlx, nel tuo file) servono solo per ispezionare quali dati sono reperibili a uno specifico url, per poter poi organizzare la tabella di raccolta dati. Nella fase di raccolta dati (Sub Caller) il contenuto di AllTables (e di Tlx) non viene piu' esaminato.
Dim uR As Long
uR = Sheets("DataColl").Cells(Rows.Count, 1).End(xlUp).Row << esistente
Range("A" & uR + 1).Select
Selection.EntireRow.Delete
Next I
AllTabs = GimmeTablesArr(WPage, myUrl) 'Ottieni la matrice delle tabelle
If Not IsEmpty(AllTabs(1)) Then '<<< IF /END IF Aggiuntivo
For J = 2 To Last1 'Cerca l'intestazione di ogni colonna...
myHead = Cells(1, J).Value
For K = 1 To UBound(AllTabs) '... in tutte le tabelle della pagina...
For L = 1 To UBound(AllTabs(K)) '.... in tutte le righe di ogni tabella
'Se "Trovato" allora scrivi il valore:
If InStr(1, AllTabs(K)(L, 1), myHead, vbTextCompare) = 1 Then
If Cells(I, J) = "" Then Cells(I, J) = AllTabs(K)(L, 2)
End If
Next L
Next K
Next J
End If
Next P
Option Explicit
Dim WPage As Object
Sub PrintTables() ' questa mi serve per sapere quali e quante tabelle ho in ogni Isin da scaricare
Dim myIsin As String
Dim I As Integer, J As Integer
Dim Tlx As Worksheet
Dim myUrl As String
Application.DisplayAlerts = False
'Crea Driver:
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.ChromeDriver")
End If
WPage.Start
With WPage
Sheets("AllTables").Select
Range("A:M").ClearContents
Cells(1, 1) = "ETF tabelle "
myIsin = "LU0476289623" ' è un Etf
myUrl = "https://www.morningstar.it/it/etfs/default.aspx" & myIsin
.Window.Maximize
.Get myUrl
.Wait 1500
.FindElementById("onetrust-accept-btn-handler").Click ' cookies
.Wait 1500
.FindElementById("btn_individual").Click ' individuale
.Wait 1500
.FindElementById("quoteSearch").Click
.SendKeys myIsin
.Wait 1000
.FindElementByCss(".ac_results").Click
.Wait 1500
Call GetAllTablesArr(myUrl, 1, 1) 'Posiziona in colonna A
.Wait 1500
End With
WPage.Close
WPage.Quit
Range("A:M").Select
Selection.Columns.AutoFit
Set WPage = Nothing
MsgBox ("Informazioni raccolte...")
Application.DisplayAlerts = True
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
'' Call GetAllTablesArr(myUrl, 1, 1) 'Posiziona in colonna A OLD
Call GetAllTablesArr(WPage.Url, 1, 1) 'Posiziona in colonna A NEW
Sub GetModTablesArr(myUrl As String, Optional rNum0 As Long = 1, Optional cNum0 As Long = 1, Optional TabList As String)
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
If InStr(1, TabList & String(10, "#"), Format(I, "000"), vbTextCompare) > 0 Or Len(TabList) = 0 Then
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
End If
Next I
Debug.Print "FINE", RNum, Format(Timer - myTim, "0.00"), myUrl
End Sub
Call GetModTablesArr(WPage.Url, 1, 1, "001; 003; 009; 021")
Call GetModTablesArr(WPage.Url, 1, 1)
Torna a Applicazioni Office Windows
Prelevare dati da www.forebet.com usando i Driver Selenium Autore: AndreaDeBiagi |
Forum: Applicazioni Office Windows Risposte: 5 |
Catalogazione pratiche collegate a pdf con doppio click Autore: systemcrack |
Forum: Applicazioni Office Windows Risposte: 22 |
Importare anche gli url con selenium Autore: aggittoriu |
Forum: Applicazioni Office Windows Risposte: 3 |
Visitano il forum: Gianca532011 e 17 ospiti