Introduction

This project is not earth shattering or revolutionary, it is simply a means of
coming to terms with ASP.NET and C# development on my part, and to hopefully
expose some knowledge and ideas to others.

This project began with the need to create an intranet portal that contained,
among other things, the local weather forecast. The design for the forecast
information was to be just like a local TV station’s web site. Since I could
not use their site, nor was paying for a service to provide the information an
option, it was determined that screen scrapping the local TV site would be a
good solution. I decided this would be a good introduction the .NET world so I
used ASP.NET with C# as the coding language.

WARNING

It should go without saying that screen scraping is not the best solution in
many cases. You are completely at the mercy of the third party site, if the
layout changes, you must rework you solution. It may also present some legal
question as to your rights to use someone else’s work.

Aquire the HTML

Using the .NET library it was easy to aqurire the HTML from the site. As can be
seen we just need to create a WebResponse object and feed the
ResponseStream
into a instance of StreamReader. From there I parse through it to remove the
empty lines and assign the result to a string. I'm using StringBuilder.Append
method as an alternative to appending to the string based on the recommendation
of Charles Petzold in
Programming Microsoft Windows with C#. Here he demonstrates the using
the StringBuilder is 1000x faster than appending to a string.

// Open the requested URL
WebRequest req = WebRequest.Create(strURL);
// Get the stream from the returned web response
StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());
// Get the stream from the returned web response
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string strLine;
// Read the stream a line at a time and place each one
// into the stringbuilder
while( (strLine = stream.ReadLine()) != null )
{
// Ignore blank lines
if(strLine.Length > 0 )
sb.Append(strLine);
}
// Finished with the stream so close it now
stream.Close();
// Cache the streamed site now so it can be used
// without reconnecting later
m_strSite = sb.ToString();

Extract the tables

After the text has been acquired it is simply a matter of extracting and
returning the substring. To fix the relative path of the images I run the
substring through another method to insert the absolute path before returning
it.

Conclusion

The complete site used ADO.NET to connect to a SQL Server database and
provide the viewer with schedule and appointment information as well
as corporate information. They also had the ability to add events to their
calendar. For simplicity I choose not include these features in this sample. I
just wanted to share a beginner C# and ASP.NET exploration to give others
some ideas.

How did this get approved? There is no where near enough content and discussion for this to qualify as an article. Take away the screen shots and code snippets and you have a few sentences to cover an immense topic. There are also many, many, many examples available for ASP.NET. You have not added anything new, different or even interesting. --Remember this message! It bounce back to you.