System.Text.RegularExpressions.Regex

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I would like to know how to be able to filter out specific information on a
given website page irregardless if the content or formating of the webpage
changes.

I am retrieving the temperature, humidity, and dewpoint information from the
following website.
"http://text.weatheroffice.ec.gc.ca/forecast/city_e.html?qc-147&unit=m"
Right now with the code below if the temperature (value) information is not
in the same place following the Temperature match, it won't work any more.
Any help would be appreciated.
Regards,
Cannucci

PS: I have included the following code as a reference to my question.

// Get web page from Enviroment Canada site for the Montreal URL in text
mode.
Set req =
System.Net.WebRequest.Create("http://text.weatheroffice.ec.gc.ca/forecast/city_e.html?qc-147&unit=m");
Set response = req.GetResponse();
Set stream = response.GetResponseStream();
Set sr = CreateInstance("mscorlib", "System.IO.StreamReader", stream);
contents = sr.ReadToEnd();

// Use regular expression to find the Temperature Value for the Montreal
area.
Set lastmatch =
CreateInstance("System","System.Text.RegularExpressions.Regex","<dt>Temperature:</dt>\n <dd>((.|\n)*?)&deg");
Temp = lastmatch.Match(contents).Groups.Item(1).ToString();

Set lastmatch =
CreateInstance("System","System.Text.RegularExpressions.Regex","<dt>Humidity:</dt>\n <dd>((.|\n)*?)%");
Humidity = lastmatch.Match(contents).Groups.Item(1).ToString();

Set lastmatch =
CreateInstance("System","System.Text.RegularExpressions.Regex","<dt>Dew
Point:</dt>\n <dd>((.|\n)*?)&deg");
DewPoint = lastmatch.Match(contents).Groups.Item(1).ToString();

// Release the external resources
response.close();
sr.Close();
 
I'm not going to answer your actual question because I don't believe
that you are taking the corrct approach.

I recommend that you use a "Web Service" for getting this weather data
rather than trying to strip it out of HTML pages like you are doing. A
simple web search for "Weather Web Service" should come up with some
good options.

Stripping data off of HTML via Regular Expressions is never a good idea
because the format of the data can change at any time and your
application breaks. Web services are better because they use published
APIs and provide you with exactly what you need without requiring you
to load the entire webpage that you didn't even need either.
 
Hi Nick,

Thanks for your recommendation, although I had already looked into this
possibility, the only solution I had found was to pull ASCII files from the
NOAA ftp server. The problem is with interfacing with a custom program which
processes and outputs to the electronic display. This custom program is based
on HP Vee Pro.

Regards,
Cannucci
 
Back
Top