c#获取网页源代码

c#获取网页源代码

 1         /// <summary>
 2         /// 获取html信息
 3         /// </summary>
 4         private string GetHtmlText(string url)
 5         {
 6             WebRequest req = WebRequest.Create(url);
 7             WebResponse res = req.GetResponse();
 8             Stream resStream = res.GetResponseStream();
 9             StreamReader sr = new StreamReader(resStream, Encoding.UTF8);
10             string contentHtml = sr.ReadToEnd();    //读取网页的源代码   
11             return contentHtml;
12         }    

根据StreamReader,根据流直接读取网页源代码

posted on 2015-08-13 11:07  凝冰  阅读(325)  评论(0编辑  收藏  举报