Basic Screen scraping sample

16 06 2008

“Screen scraping” means grab the contents of a web page. ASP.NET makes scraping easy. You can grab the contents of any site and then use that contents according to your needs.

For example, you can grab the contents of stock exchange site and then extract useful information from that one. We will remain at very basic level in this article. In future we will move to some useful practical knowledge.

Scraping through ASP.NET:

You have to include following name spaces

1. System.Net (For WebClient)      2. System.Text (For UTF8Encoding)

// make object of WebClient.

WebClient MyClient = new WebClient();

// the url of site whose contents you want to grab.
string Url = “http://www.google.com.pk”

// to get string, as downloaded data returns byte[]
UTF8Encoding MyEncoding = new UTF8Encoding();

// Calling DownloadData function. It will return all contents inform of byte[] array. You can get the                    string by calling GetString method of UTF8Encoding object
string str = MyEncoding.GetString(MyClient.DownloadData(Url));

In this string you have all the contents. you can extract any thing from it.

Enjoy.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: