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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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