Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2005

Tip: Looking for answers? Try searching our database.

System.Text.RegularExpressions.Regex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mauro - 08 Sep 2005 17:11 GMT
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();
Nick Hertl - 08 Sep 2005 19:41 GMT
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.
Mauro - 09 Sep 2005 19:37 GMT
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

> I'm not going to answer your actual question because I don't believe
> that you are taking the corrct approach.
[quoted text clipped - 9 lines]
> APIs and provide you with exactly what you need without requiring you
> to load the entire webpage that you didn't even need either.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.