根据url爬取网页数据

using System.IO;
using System.Net;
using System.Text;

namespace Common
{
    public class Crawler
    {
        //爬虫类
        /// 
        /// 根据url爬取网页数据
        /// 
        /// 
        /// 
        public static string WebTextUrl(string url)
        {
            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();

            //定义一个流来保存获得的内容
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);

            string text = reader.ReadToEnd();
            return text;

        }
    }
}

你可能感兴趣的:(根据url爬取网页数据)