Output webpage content : Web Crawler « Network « C# / C Sharp






Output webpage content



using System.Net;
using System;
using System.IO;
public class WebPagesApp {
    [STAThread]
    public static void Main(string[] args) {
        string s = "http://www.microsoft.com";
        Uri uri = new Uri(s);
        WebRequest req = WebRequest.Create(uri);
        WebResponse resp = req.GetResponse();
        Stream str = resp.GetResponseStream();
        StreamReader sr = new StreamReader(str);

        string t = sr.ReadToEnd();
        int i = t.IndexOf("<HEAD>");
        int j = t.IndexOf("</HEAD>");
        string u = t.Substring(i, j);
        Console.WriteLine("{0}", u);
    }
}

           
       








Related examples in the same category

1.Set the BaseAddress for WebClient
2.Build the DownloadString
3.Download a web page in a thread
4.Create GetResponse from WebRequest
5.Check the ContentType
6.MiniCrawler: A skeletal Web crawler