Hello everyone from Maurizio
My problem is this:
With the use of the vba I am trying to extract data from a web page, and since I used (Internet Explorer) before but I still have problems viewing the entire web page.
I decided to change the method and using the windows api I was able to open the Google Chrome browser.
But now I would like to know how to download the data from this Portal as well.
(P.s) I don't mean that you do all the work for me
For me it would be enough just to understand how to download the first two data of this sector:
My problem is this:
With the use of the vba I am trying to extract data from a web page, and since I used (Internet Explorer) before but I still have problems viewing the entire web page.
I decided to change the method and using the windows api I was able to open the Google Chrome browser.
But now I would like to know how to download the data from this Portal as well.
(P.s) I don't mean that you do all the work for me
For me it would be enough just to understand how to download the first two data of this sector:
VBA Code:
#If VBA7 Then '!!! ON TOP OF THE VBA MODULE !!!!
'PtrSafe <----Per Sistemi a 64 Bit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub Previsioni_Weather()
On Error GoTo finish
Dim chromePath As String
Dim CollA As Object, CollB As Object
Dim cSrc As String, cIW As Single, myStart As Single
Dim IE As Object, SecFl As Boolean
myStart = Timer
Debug.Print ">>>>", Timer
X = Foglio1.Range("G1").Value & ""
Y = Foglio1.Range("I1").Value & ""
chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
Shell (chromePath & myURL & "https://www.worldweatheronline.com/" & X & "/" & Y & "" & "/it.aspx")
'Set IE = CreateObject("IE.application")
'Set IE = New InternetExplorer
Set IE = CreateObject("Chrome.Chrome")
Debug.Print TypeName(IE)
'
With IE
Debug.Print myURL, Format(Timer - myStart, "0.00")
.navigate chromePath & myURL
'.Visible = False 'meglio TRUE
.Visible = True
End With
'ReDO:
Set IE = chromePath & myURL
With IE
.Silent = True
.navigate chromePath & myURL
.Visible = True
Do
DoEvents
Loop Until .readyState = READYSTATE_COMPLETE
On Error Resume Next
With IE.document
Set OggCol = .getElementsByClassName("col-sm-12")
Set OggCol1 = .getElementsByClassName("mt-0 mb-0")
End With
Set SH = ThisWorkbook.Sheets("Foglio1")
With SH
'--------------------------------------------------------------
'Qui Prelevo Questo : "San Giusto Canavese Weather, Piemonte, IT" _
Dalla Pagina Web
.Cells(1, 1) = OggCol(0).innerText
'Qui Prelevo Questi Dati : " Humidity - Cloud - Pressure - _
Sunrise - Moonrise - Phase? - Sunset - oonset - Illum" _
Dalla Pagina Web
.Cells(9, 2) = OggCol(4).innerText
.Cells(10, 2) = OggCol(5).innerText
.Cells(11, 2) = OggCol(6).innerText
.Cells(12, 2) = OggCol(7).innerText
.Cells(13, 2) = OggCol(8).innerText
.Cells(14, 2) = OggCol(9).innerText
.Cells(9, 3) = OggCol(10).innerText
.Cells(10, 3) = OggCol(11).innerText
.Cells(11, 3) = OggCol(12).innerText
.Cells(12, 3) = OggCol(13).innerText
.Cells(13, 3) = OggCol(14).innerText
.Cells(14, 3) = OggCol(15).innerText
.Cells(9, 4) = OggCol(16).innerText
.Cells(10, 4) = OggCol(17).innerText
.Cells(11, 4) = OggCol(18).innerText
.Cells(12, 4) = OggCol(19).innerText
.Cells(13, 4) = OggCol(20).innerText
.Cells(14, 4) = OggCol(21).innerText
'---------------------------------------------------------------
.Cells(5, 2) = OggCol1(0).innerText
.Cells(6, 2) = OggCol1(1).innerText
.Cells(7, 2) = OggCol1(2).innerText
'-------------------------------------
End With
SH.Range("B23").WrapText = True
SH.Range("A1").Select
IE.Quit
End With
Set IE = Nothing
finish:
End Sub