How to extract data from this webpage clay in this way

Maury1704

New Member
Joined
Jan 13, 2016
Messages
24
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:


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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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:


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

That's all !
Thanks in advance for all the help you will want to give me on this
Greetings from A.Maurizio

screenshot 8 — Postimages
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top