Import HTTP web text into string (1 Viewer)

Trocergian

Registered User.
Local time
Yesterday, 18:06
Joined
Apr 6, 2009
Messages
16
I am using a wep API to get some weather data. It opens a web page with a text string similar to this:

{"count":1,"data":[{"app_temp":107.9,"aqi":43,"city_name":"Fate","clouds":4,"country_code":"US","datetime":"2023-07-13:20","dewpt":74.9,"dhi":120.98,"dni":915.14,"elev_angle":67.43,"ghi":957.76,"gust":22.5,"h_angle":25.7,"lat":32.9432,"lon":-96.3904,"ob_time":"2023-07-13 20:12","pod":"d","precip":0,"pres":988,"rh":50,"slp":1007.89026,"snow":0,"solar_rad":957.7,"sources":["rtma","radar","satellite"],"state_code":"TX","station":"F4376","sunrise":"11:27","sunset":"01:35","temp":96.1,"timezone":"America/Chicago","ts":1689279151,"uv":9.523339,"vis":9.9,"weather":{"description":"Clear sky","code":800,"icon":"c01d"},"wind_cdir":"S","wind_cdir_full":"south","wind_dir":190,"wind_spd":14.6}]}

My question is how do I get a web page's text into a text string so I can parse the information?
(I know how to parse the string once I have it, it's somehow getting it into the variable.)
I was wondering is there is some variation of a strVariable = webpageobject("https://whatever.page.info") type of thing?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:06
Joined
Oct 29, 2018
Messages
21,474
Hi. Try to do search for the HTTPRequest class.
 

Edgar_

Active member
Local time
Yesterday, 18:06
Joined
Jul 8, 2023
Messages
431
Once you perform the HTTPRequest, you can parse the string with this recommended library:
Like:
Set ApiResponse = ParseJson(.ResponseText)
It will put your response into a dictionary that you can query like:
Debug.Print ApiResponse("data")(1)("app_temp")
And it will return the value of the key app_temp
 
Last edited:

Users who are viewing this thread

Top Bottom