Moderatori: Anthony47, Flash30005
Io ho un Isin, es AT0000383864; vorrei ottenere, partendo dalla pagina web xyzabc.com, le seguenti informazioni:
1)..
2)..
3)..
Oggi faccio così:
.... ... ...
ma ottengo ... ... ...
Come si puo' fare in modo rapido e indolore?
Questo funziona bene MA su 400 titoli impiega 1ora e passa . Tutto con Selenium /tuo metodo .
Ora l'dea era di abbreviare i tempi di scarico . ??? La logia di scarico dati è quella del post 1 .
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, ur As Long
Sheets("DataColl").Activate
ur = Cells(Rows.Count, 1).End(xlUp).Row
' converti isin a maiuscolo
Dim x As Object
For Each x In Range("A2:A" & ur)
x.Value = UCase(x.Value)
Next
'Crea Driver:
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.ChromeDriver")
WPage.Start "Chrome"
End If
With WPage
LastA = Cells(Rows.Count, "A").End(xlUp).Row 'Quanti Isin?
Last1 = Cells(1, Columns.Count).End(xlToLeft).Column 'Quante colonne?
'
Range("B2:P" & LastA).ClearContents
'For P = 1 To 6 'Cerca in tutti gli URL
For i = 2 To LastA ' per ogni Isin dato
myIsin = Cells(i, 1)
Dim url1 As String, url2 As String, url3 As String, url4 As String, url5 As String, url6 As String
' nota i links funzionano mettendoci -obbligatoriamente- anche l'isin
url1 = "https://www.borsaitaliana.it/borsa/obbligazioni/mot/obbligazioni-in-euro/scheda/" & myIsin & ".html?lang=it"
url2 = "https://www.borsaitaliana.it/borsa/obbligazioni/mot/obbligazioni-in-euro/dati-completi.html?isin=" & myIsin & "&lang=it"
url3 = "https://www.borsaitaliana.it/borsa/obbligazioni/extramot/scheda/" & myIsin & ".html?lang=it"
url4 = "https://www.borsaitaliana.it/borsa/obbligazioni/extramot/dati-completi.html?isin=" & myIsin & "&lang=it"
url5 = "https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/" & myIsin & ".html?lang=it"
url6 = "https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/dati-completi.html?isin=" & myIsin & "&lang=it"
>>>>>????? >>>>>><<< <
[color=#FF0040]
If Cells(i, 3) = "" Then
.Get url1
.Get url2
GoTo 10
WPage.Close
Stop
Else 'If Cells(i, 3) = "" Then
WPage.Get , url3
WPage.Get url4
GoTo 10
WPage.Close
End If
If Cells(i, 3) = "" Then
WPage.Get url5
WPage.Get url6
GoTo 10
WPage.Close
End If
[/color]
10:
AllTabs = GimmeTablesArr(WPage, myUrl) 'Ottieni la matrice delle tabelle
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...
On Error Resume Next
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
On Error GoTo 0
Next L
Next K
Next J
Next i
' Next P
End With
'Quit Selenium
WPage.Quit
'allinea a dx e rendi numeri a stringa
ur = Sheets("DataColl").Cells(Rows.Count, 1).End(xlUp).Row
With Sheets("DataColl")
.Range("D2:O" & ur).Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With
With Sheets("DataColl")
.Range("B2:C" & ur).Select
With Selection
.NumberFormat = "@"
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With
Set WPage = Nothing
MsgBox ("Informazioni raccolte...")
End Sub
Torna a Applicazioni Office Windows
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 43 ospiti