ASP.Net抓取页面

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


        string sException = null;
        string sRslt = null;
        WebResponse oWebRps = null;
        WebRequest oWebRqst = WebRequest.Create("http://www.baidu.com");
        oWebRqst.Timeout = 50000;
        try
        {
            oWebRps = oWebRqst.GetResponse();
        }
        catch (WebException ex)
        {
            sException = ex.Message.ToString();
            Response.Write(sException);
        }


        finally
        {
            if (oWebRps != null)
            {
                StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                sRslt = oStreamRd.ReadToEnd();
                oStreamRd.Close();
                oWebRps.Close();
            }
        }
        Response.Write(sRslt);

posted @ 2009-07-26 08:56  小开的一天  阅读(320)  评论(0编辑  收藏  举报