Web Scraping

NiftyTrader

New Member
Joined
Jul 31, 2015
Messages
15
Hello,

I need help trying to get the 1st line of the following 10-day forecast. Here is my code to get the forecast for Miami, FL on Weather.com. I am not able to get the current date or the first date in the summary. Please help. Thanks and take care.

Sub MiamiWeather()

Dim ieObj As InternetExplorer
Dim htmlEle As IHTMLElement
Dim i As Integer

i = 1

Set ieObj = New InternetExplorer
ieObj.Visible = False
ieObj.navigate "Miami, FL 10-Day Weather Forecast - The Weather Channel | Weather.com"

Application.Wait Now + TimeValue("00:00:05")

For Each htmlEle In ieObj.document.getElementsByClassName("_350ZO")(0).getElementsByTagName("summary")
With ActiveSheet
.Range("A" & i).Value = htmlEle.Children(0).textContent
End With

i = i + 1
Next htmlEle

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Does anyone know how to make this code fast to render the results? Any help is much appreciated. Thanks!

Sub MiamiWeather()

Dim HTTP As Object, HTML As Object, i As Integer, j As Integer

Set HTML = CreateObject("HTMLFILE")
Set HTTP = CreateObject("MSXML2.XMLHTTP")

myURL = "Miami, FL 10-Day Weather Forecast - The Weather Channel | Weather.com"

HTTP.Open "GET", myURL, False
HTTP.send

HTML.body.innerHTML = HTTP.responseText

Set objCollection = HTML.getElementsByTagName("p")
i = 0

Do While i < objCollection.Length
If objCollection(i).getAttribute("data-testid") = "wxPhrase" Then
j = j + 1
Range("A" & j) = objCollection(i).PreviousSibling.PreviousSibling.FirstChild.innerText
Range("B" & j) = objCollection(i).PreviousSibling.FirstChild.innerText

End If
i = i + 1
Loop

Set HTML = Nothing
Set HTTP = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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