Cambia Research - Supporting the Microsoft .NET Developer Community Supporting the Microsoft .NET Developer Community  

     | Home  | Articles  | Categories  | Coders  | Search  | Submit  | Contact Us    
If your project doesn't work, look for the part that you didn't think was important. --Arthur Bloch

Share Your Knowledge! -- Create and submit your articles the easy way with WebWriter.

Updated:04:21 PM CT Mar 05, 2007
Posted:03:54 PM CT Mar 05, 2007

How to scrape or download a webpage using C#

Author: KTB

SnippetC#Visual Studio.NETASP.NET

 Summary

Here I intend to show you how you can use C# and System.Net.HttpWebRequest to scrape or download a webpage.

Similar code can also be used to post forms which utilize both the get and post form methods by adding a few extra lines of code.

Example: Using HttpWebRequest Object

string url = "http://google.com";
string strResult = "";
			
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);

objResponse = objRequest.GetResponse();

using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
	strResult = sr.ReadToEnd();
	// Close and clean up the StreamReader
	sr.Close();
}

// Display results to a webpage
Response.Write(strResult);

Add New Comment
How to scrape or download a webpage using C#
Chris09 Jun 07, 23:29Reply 
re: How to scrape or download a webpage using C#
Steve Lautenschlager10 Jun 07, 12:00Reply 
How to scrape or download a webpage using C#
Peter29 May 08, 3:44Reply 
CR Comments by Cambia Research
advertisement
 
(ktb)


 
Copyright © Cambia Research 2002-2007. All Rights Reserved. steve [ at ] cambiaresearch.com