I am trying to copy specific data from a weather forecast table on https://www.wunderground.com. To be more exact, I am trying to get the Time and the Cloud Cover in Excel in a tabular format (but for now any format will do) from a link like https://www.wunderground.com/hourly/ro/mizil/45.00,26.44/date/2020-04-15. So far I have tried many ways to get that specific data but I am falling short (I am new to web scraping with VBA). The concepts and commands are quite clear to me and they have worked for other sites, but for this site I am at wits' end. Currently, I am using:
Sub WeatherScrap()
Range("A1").Select
Dim mainlink As String Dim http As New XMLHTTP60, html As New HTMLDocument Dim CloudCover As Object
mainlink = "https://www.wunderground.com/hourly/ro/mizil/45.00,26.44/date/2020-04-15"
With http
.Open "GET", mainlink, False
.send
html.body.innerHTML = .responseText
End With
For Each CloudCover In html.getElementsByClassName("wu-value wu-value-to")
ActiveCell.Value = CloudCover.innerText
ActiveCell.Offset(1, 0).Select
Next CloudCover
End Sub
I am obviously not referencing the right classes, tags or IDs on the html (I have tried with many so far, but none retrieve the desired data). The html element on the site is:
<lib-display-unit _ngcontent-app-root-c213="" _nghost-app-root-c122="" class="ng-star-inserted"><span _ngcontent-app-root-c122="" class="test- wu-unit wu-unit-chance ng-star-inserted"><!----><!----><!----><span _ngcontent-app-root-c122="" class="wu-value wu-value-to">100</span> <span _ngcontent-app-root-c122="" class="wu-label"><span _ngcontent-app-root-c122="" class="ng-star-inserted">%</span>
For now, just understanding how to fetch the Cloud Cover percentage from the table would suffice. Can anyone help? Thanks a lot!