Screen Scraping in ASP.NET
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Current Tip:
Screen Scraping in ASP.NET
 
[prev. Lesson]  Deploying Web.Config [next Lesson]  Refrencing the Root Path/URL
Screen Scraping in ASP.NET  by: Salman

Simply cut and paste the code below to dynamically retreive html from web pages. Screen scraping in ASP.NET could not be any easier. With a little regex knowledge you could even filter the html and display links on your webpage.

Live Demo

Class Library References

  • System.Net
  • System.IO

    <%@ Page language="c#"%>
    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.IO" %>
    <script runat="server" lang="c#">
    private void Page_Load(object sender, System.EventArgs e)
    {
    //Retrieve URL from user input box
    if(Page.IsPostBack)
    litHTMLfromScrapedPage.Text = GetHtmlPage( tbURL.Text );
    }
    public String GetHtmlPage(string strURL)
    {
    // the html retrieved from the page
    String strResult;
    WebResponse objResponse;
    WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
    objResponse = objRequest.GetResponse();
    // the using keyword will automatically dispose the object 
    // once complete
    using (StreamReader sr = 
    new StreamReader(objResponse.GetResponseStream()))
    {
    strResult = sr.ReadToEnd();
    // Close and clean up the StreamReader
    sr.Close();
    }
    return strResult;
    }
    
    </script>
    <HTML>
    <HEAD>
    <title>Page Scrape in C# - CSharpFriends</title>
    </HEAD>
    <body>
    <form runat="server">
    <p>Enter the URL to the page you want to scrape (include the http://)</p> <asp:TextBox ID="tbURL" Runat="server" /><asp:Button ID="btnSumbit" Text="Go!" Runat="server" /> <br>
    <br>
    <asp:Literal ID="litHTMLfromScrapedPage" Runat="server" />
    </form>
    </body>
    </HTML>
  •    
    Current Tip:
    Screen Scraping in ASP.NET
     
    [prev. Lesson]  Deploying Web.Config [next Lesson]  Refrencing the Root Path/URL



    Today's Top Movers

    Yesterday Top Movers


    Monthly Leaders

    Top Members

    Great Offers
    .net hosting
    Go To My Pc
    Remote Pc Control
    C#
    ad server
    snadtech GoToMyPc

    Top of Page

    Advertise | SiteMap | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center