Use screen-scraping to get the temperature for a city
- Last UpdatedJul 22, 2024
- 1 minute read
Note: This sample script includes a reference to a public website as an example. You may need to replace that URL with a current and verified URL.
' Screen-scraping involves downloading a web page,
' then using a regular expression to retrieve the desired data.
' Requires input string UDA me.CityState, e.g. "Los Angeles,CA"
' and output float UDA me.temperature.
dim request as System.Net.WebRequest;
dim reader as System.IO.StreamReader;
dim regex as System.Text.RegularExpressions.Regex;
dim match as System.Text.RegularExpressions.Match;
request = System.Net.WebRequest.Create
(
"http://www.srh.noaa.gov/data/forecasts/zipcity.php?inputstring=" +
System.Web.HttpUtility.UrlEncode(me.CityState)
);
reader = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
regex = new System.Text.RegularExpressions.Regex("<br><br>(.*)°F<br>");
match = regex.Match(reader.ReadToEnd());
me.temperature = match.Groups(1);