Screen Scrap of Web Page

How about getting the contents of  url and set it in your own page? Well, you can use to do that. Here is the codebehind code in C#

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

public partial class tv_scrap : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void btnSubmit_Click(object sender, EventArgs e)
String strURL=txtUrl.Text;
String strHTML =String.Empty;

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
objWebRequest.Method = “GET”;
HttpWebResponse objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(objWebResponse.GetResponseStream());

strHTML = streamReader.ReadToEnd();
txtResponse.Text = strHTML;
lblResponse.Text = strHTML;


and the HTML code,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="scrap.aspx.cs" ValidateRequest="false" Inherits="tv_scrap" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Screen Scraping</title>
    <form id="form1" runat="server">
    <asp:TextBox ID="txtUrl" runat="server" ></asp:TextBox>
    <asp:Button ID="btnSubmit" Runat="server" Text="Scrape Me!" OnClick="btnSubmit_Click" />
    <asp:TextBox ID="txtResponse" Runat="server" Width="800" Height="300" TextMode="MultiLine" />
    <asp:Literal ID="lblResponse" Runat="server" />

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s