Hi all! I'm trying to pull weather for certain locations. I've got the scraping part down. I'm having trouble controlling the location; results are intermittent if I use a hard coded URL or if using cells in the worksheet to complete the URL. Sometimes it if trying for Seattle, WA it ends up in Brisbane, Spain or some other random place. My thought is to use the search function on the website but having trouble hitting the right spot. Closest I've gotten is the Bing search bar at the top of the page.
When I Inspect Element this is what I saw:
I've got this bit to open the page and wait working find.
I can't for the life of me figure how to interact with the location search parts! I've tried
But get a run time error 91 Object Variable or with block Variable not set. I am an HTML novice and know enough VBA to make me dangerous. I appreciate any help and education you can provide!
When I Inspect Element this is what I saw:
HTML:
' THE BUTTON:
<a role="button" href="/en-us/weather/places?ru=/en-us/weather/today">Places</a>
'THE BLANK SPACE TO TYPE A LOCATION:
<input name="q" class="query" accesskey="L" aria-autocomplete="list" aria-label="Search for Location / City" type="search" maxlength="250" placeholder="Search for Location / City" value="" data-m='{"i":56,"p":55,"n":"weaautosuggest","y":10,"o":1}' data-id="56" autocomplete="off" data-autosuggestdelay="100" data-seemoretext="Press <Enter> to see more" data-auto-suggest-settings='{"market":"en-us","mode":"AS","baseurl":"/en-us/weather/today","action":"addfavorite","method":"get","selector":null,"urltype":"Weather","formcode":"PRWLAS","lat":43.6242,"lon":-116.289}'>
' SEARCH BUTTON:
<button title="Search" class="searchbtn" aria-label="search" type="submit" data-m='{"i":57,"p":55,"n":"wealocationsearch","y":11,"o":2}' data-id="57">
<span class="x-screen-reader">Search</span>
</button>
I've got this bit to open the page and wait working find.
VBA Code:
Sub check()
Dim oHTML_Element As IHTMLElement
Dim anchorElement As HTMLAnchorElement
Dim oIE As InternetExplorer
Dim IE As Variant
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.msn.com/en-us/weather"
While IE.readyState <> READYSTATE_COMPLETE And IE.readyState <> READYSTATE_LOADED
DoEvents
Wend
Application.Wait (Now() + TimeValue("00:00:03"))
End Sub
I can't for the life of me figure how to interact with the location search parts! I've tried
VBA Code:
oIE.document.getElementsByClassName("query")(0).Click
'and
oIE.document.getElementsByClassName("searchbtn")(0).Click
But get a run time error 91 Object Variable or with block Variable not set. I am an HTML novice and know enough VBA to make me dangerous. I appreciate any help and education you can provide!