C#asp.net 采集或者 生成静态 HTML 思路办法

        string url = "HTTP://WWW.CAOTU66.COM";

        string Html = string.Empty;//初始化新的webRequst
        HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);

        Request.KeepAlive = true;
        Request.ProtocolVersion = HttpVersion.Version11;
        Request.Method = "GET";
        Request.Accept = "*/* ";
        Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
        Request.Referer = url;

        HttpWebResponse htmlResponse = (HttpWebResponse)Request.GetResponse();
        //从Internet资源返回数据流
        Stream htmlStream = htmlResponse.GetResponseStream();
        //读取数据流
        StreamReader weatherStreamReader = new StreamReader(htmlStream, Encoding.UTF8);
        //读取数据
        Html = weatherStreamReader.ReadToEnd();
        weatherStreamReader.Close();
        htmlStream.Close();
        htmlResponse.Close();
        //针对不同的网站查看html源文件


        Label1.Text = Html;

        string result = Html;


        // 生成的静态页的保存路径
        string savePathForStaticPage = Server.MapPath("test.html");
        StreamWriter writer = new StreamWriter(savePathForStaticPage, false, Encoding.UTF8);
        writer.Write(result);
        writer.Close();







如果是在winform里面用个 time就好做了,但是在webform里面 就比较困难;

这时候 可能需要用到 

Timer定时器


http://www.hanqichao.com/news/884.html


这篇文章有说有 怎么添加 希望能够成功






webform
桂ICP备16004754号