通过URL返回请求的内容 C#

        public static string getPageInfo(String url)
        {
            WebResponse wr_result = null;
            StringBuilder txthtml = new StringBuilder();
            try
            {
                WebRequest wr_req = WebRequest.Create(url);
                wr_result = wr_req.GetResponse();
                Stream ReceiveStream = wr_result.GetResponseStream();
                //Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
                //Encoding encode = Encoding.Unicode;
                Encoding encode = Encoding.UTF8;
                StreamReader sr = new StreamReader(ReceiveStream, encode);
                if (true)
                {
                    Char[] read = new Char[256];
                    int count = sr.Read(read, 0, 256);
                    while (count > 0)
                    {
                        String str = new String(read, 0, count);
                        txthtml.Append(str);
                        count = sr.Read(read, 0, 256);
                    }
                }
            }
            catch (Exception)
            {
                txthtml.Append("err");
            }
            finally
            {
                if (wr_result != null)
                {
                    wr_result.Close();
                }
            }
            return txthtml.ToString();
        } 


参考:

http://hi.baidu.com/qljwm/item/5122708b41ad0655e73d1904

http://www.cnblogs.com/Jiajun/archive/2012/06/16/2552103.html  网络爬虫

http://www.dezai.cn/Channel/Web/ArticleShow.aspx?AI=76467  C#抓取网页数据、分析并且去除HTML标签

http://blog.csdn.net/felomeng/article/details/1522292  爬虫/蜘蛛程序的制作(C#语言)

http://blog.csdn.net/felomeng/article/details/1522892 蜘蛛/爬虫程序的多线程控制(C#语言)

http://www.dezai.cn/Channel/Web/ArticleShow.aspx?AI=76467  C#抓取网页源代码(HTML代码)方法

 http://www.cnblogs.com/falcon-fei/archive/2012/02/29/2379881.html c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)

http://www.189works.com/article-43227-1.html  C# 抓取网页内容(转)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值