In this example you will learn to Crawl a Web Page in C#. Crawling i refers to request the web page data and get the reponse data programmatically. You can easily do this in .net.
Here is the daily code for this
Add using:
1 2 3 4 |
using System.IO; using System.Net; |
Program class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class Program { static void Main(string[] args) { WebRequest request = WebRequest.Create("http://www.csharp-console-examples.com/"); using (WebResponse response = request.GetResponse()) { using (StreamReader responseReader = new StreamReader(response.GetResponseStream())) { string responseData = responseReader.ReadToEnd(); using (StreamWriter writer = new StreamWriter(@"D:\\sample\sample.html")) { writer.Write(responseData); } } } } } |