Recent Posts

Monday, July 21, 2008

How to screen scrap data from Asp.Net application

In the following example it gets all the data from the website and displays it in a text box.
You can later manupulate that data for your any other use.

First on any .aspx page just put one text box named "myWebText" and copy and paste the
following code in your code behind page:

Then run the application it will get all the data from the url to the text box for further use

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;

public partial class ScreenScrap : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
myWebText.Text = readHtmlPage("");
private String readHtmlPage(string url)
String result;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
result = sr.ReadToEnd();
// Close and clean up the StreamReader
return result;

Related Posts by Categories

No comments:

Post a Comment