Moderatori: Anthony47, Flash30005
Dim WPage As Object 'IN TESTA AL MODULO
Sub myCaller()
Dim myBet As String, myUrl As String
'
Start = Timer
'Crea Driver:
If WPage Is Nothing Then
' Set WPage = CreateObject("Selenium.EdgeDriver")
Set WPage = CreateObject("Selenium.CHRomedriver")
End If
'
myUrl = Sheets("Foglio1").Range("B3")
Sheets("Foglio1").Select
Range("A5").Resize(2000, 30).Clear
Call GetAllTablesLE(myUrl, 5, 3) 'Posiziona in riga 5, colonna C
SQuit:
WPage.Quit
Set WPage = Nothing
Application.Calculation = xlAutomatic
MsgBox "Tempo: " & Format(Timer - Start, "0.00")
End Sub
Sub GetAllTablesLE(myUrl As String, Optional rNum0 As Long = 1, Optional cNum0 As Long = 1)
'Accetta h.links "relativi alla radice
Dim TBColl As Object, StrHtm As String
Dim I As Long, J As Long, myTim As Single
Dim RNum As Long, CNum As Long, HTDoc As Object
Dim iniTab As Long, finiTab As Long
'Dim TArr
Dim TDColl As Object, TRColl As Object, AColl As Object, PiPPo As Long
If WPage Is Nothing Then
Set WPage = CreateObject("Selenium.CHRomedriver")
End If
'''On Error Resume Next
reUrl:
WPage.Get myUrl
'
WPage.Wait 1000
'Carica e ricarica...
If myUrl <> WPage.Url And PiPPo < 4 Then
PiPPo = PiPPo + 1
Debug.Print "Non pronta", PiPPo, myUrl, WPage.Url
GoTo reUrl
End If
Debug.Print "Pagina pronta", PiPPo, myUrl, WPage.Url
myTim = Timer
'
Set HTDoc = CreateObject("HTMLfile") 'late binding alla html obj lib
'Crea htmlDocument:
HTDoc.Open
lenhtml = Len(WPage.PageSource)
Do
iniTab = InStr(finiTab + 1, WPage.PageSource, "<table", vbTextCompare)
finiTab = InStr(iniTab + 1, WPage.PageSource, "</table", vbTextCompare)
If iniTab = 0 Then Exit Do
StrHtm = StrHtm & Mid(WPage.PageSource, iniTab, finiTab - iniTab + 10)
Loop
HTDoc.write StrHtm
'Crea root per hLinks
Dim qmPos As Long, hlRoot As String, iHL As String
qmPos = InStr(10, myUrl & "/", "/", vbTextCompare)
hlRoot = Left(myUrl, qmPos - 1)
'
'esamina il tag richiesto:
If Not HTDoc Is Nothing Then
Set TBColl = HTDoc.getElementsByTagName("table")
RNum = rNum0: CNum = cNum0
For I = 0 To TBColl.Length - 1
RNum = RNum + 1
Cells(RNum, CNum).Value = "## Table " & I
Debug.Print "## Table " & I, Format(Timer - myTim, "0.0"), RNum
Set TRColl = TBColl(I).getElementsByTagName("tr")
RNum = RNum + 1: CNum = cNum0
For J = 0 To TRColl.Length - 1
Set TDColl = TRColl(J).getElementsByTagName("td")
For k = 0 To TDColl.Length - 1
Cells(RNum, CNum).Value = TDColl(k).innerText
Set AColl = TDColl(k).getElementsByTagName("a")
If AColl.Length > 0 Then
iHL = Replace(AColl(0).href, "about:", "", , , vbTextCompare)
If Left(iHL, 1) = "/" Then
iHL = hlRoot & iHL
End If
ActiveSheet.Hyperlinks.Add anchor:=Cells(RNum, CNum), _
Address:=iHL
End If
CNum = CNum + 1
Next k
RNum = RNum + 1: CNum = cNum0
' Debug.Print "## Table " & I, Format(Timer - myTim, "0.0"), RNum
Next J
RNum = RNum + 1
DoEvents
Next I
End If
Debug.Print "FINE-LE", RNum, Format(Timer - myTim, "0.00"), myUrl
End Sub
Function Separ(ByRef myCell As Range, Optional ByVal Seppp As String = "€", Optional DPoint As String = ".") As Single
Dim mySpl
mySpl = Split(" " & Seppp & Replace(myCell.Value, DPoint, ",", , , vbTextCompare), Seppp, , vbTextCompare)
Separ = CSng("0" & Replace(mySpl(UBound(mySpl)), " ", "", , , vbTextCompare))
End Function
=Separ(foglio1!K15)
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 |
adattare il contenuto alla pagina Autore: trittico69 |
Forum: Applicazioni Office Windows Risposte: 12 |
Visitano il forum: Nessuno e 15 ospiti