抓取网站内容 asp.net

 

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.cs.com.cn");

    myReq.Accept = "Accept-Language:   zh-cn";

    myReq.Referer = "http://www.cs.com.cn";

    myReq.MaximumAutomaticRedirections = 1;

    myReq.AllowAutoRedirect = true;

    HttpWebResponse myres = (HttpWebResponse)myReq.GetResponse();//  

    Stream resStream = myres.GetResponseStream();

    StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);

 

    Response.Write(sr.ReadToEnd()); 

 

阅:该代码可将网站首页抓取下来;

你可能感兴趣的:(asp/asp.net学习)