windows计划任务自动生成静态首页

来源:互联网 发布:域名怎么绑定esc服务器 编辑:程序博客网 时间:2024/04/29 13:31

indexplan.vbs: 脚本程序,调用ie组建执行生成首页的程序这里强调的是必须打开ie,要用到ie的组建,遨游好像不行。然后把这个脚本程序添加到windows计划任务里,设置好执行时间间隔,看你首页跟新的快慢了,自己把握。

Dim IESet IE = CreateObject("InternetExplorer.Application")ie.navigate("http://localhost:80/createindex.asp")-这里在服务器换成你的域名指向你的生成文件ie.visible=0Set IE = Nothing
ASP版本
Server.ScriptTimeOut=9999999 Function BytesToBstr(body,Cset)'防止乱码函数dim objstreamset objstream = Server.CreateObject("adodb.stream")objstream.Type = 1objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Charset = CsetBytesToBstr = objstream.ReadTextobjstream.Closeset objstream = NothingEnd FunctionFunction GetHTTPPage(Url)'获取Html代码函数err.clearOn Error Resume Nextdim http set http=Server.createobject("Microsoft.XMLHTTP") Http.open "GET",url,false Http.send()if Http.readystate<>4 thenexit function end if GetHTTPPage = bytesToBSTR(Http.responseBody,"GB2312")set http = NothingIf Err Then   response.write err.description   Response.Write "<br><br><p align='center'><font color='red'><b>无法抓取本页面信息!!!</b></font></p>"End IfEnd functionUrl="http://www.xxxxx.com/index.asp"strHtml=GetHTTPPage(Url)filename=server.mappath("index.html")if strHtml<>"" then'读取到首页源代码    set fso = Server.CreateObject("scripting.FileSystemObject")if fso.FileExists(filename) then '静态首页存在,删除旧页面   fso.DeleteFile filename    set fout = fso.CreateTextFile(filename,true,False)'重新生成   fout.write strHtml   fout.close   set fout=nothing   set fso=nothing else   set fout = fso.CreateTextFile(filename,true,False)   fout.write strHtml   fout.close   set fout=nothing   set fso=nothing end if end if
ASP.NET版本:
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Text;using System.Text.RegularExpressions;using System.IO;using System.Net;public partial class CreatIndex : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        //index.html页面存在先删除旧页面,然后生成新页面        if (File.Exists(@"E:/product/index.html"))        {            File.Delete(@"E:/product/index.html");            string URL = "http://www.xxxx.com";            string Content = GetHtmlContent(URL);            CreateIndex(Content);        }        //index.html页面不存在直接生成        else        {            string URL = "http://www.xxxx.com";            string Content = GetHtmlContent(URL);            CreateIndex(Content);        }    }    //生成index.html页面    protected void CreateIndex(string con)    {           string IndexPath = @"E:/product/index.html";             //StreamWriter sr = File.CreateText(@"E:/product/index.html");            StreamWriter sr = new StreamWriter(IndexPath, true, System.Text.Encoding.GetEncoding("GB2312"));            Response.Write("生成Index.html文件成功。生成时间:" + System.DateTime.Now);            sr.WriteLine(con);            sr.Close();    }    //读取网页源代码    private string GetHtmlContent(string Url)    {        string strHtmlContent = "";        try        {            //声明一个HttpWebRequest请求            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);            //连接超时时间            request.Timeout = 500000;            request.Headers.Set("Pragma", "no-cache");            HttpWebResponse response = (HttpWebResponse)request.GetResponse();            Stream streamHtmlCode = response.GetResponseStream();            Encoding encoding = Encoding.GetEncoding("GB2312");            StreamReader streamReader = new StreamReader(streamHtmlCode, encoding);            strHtmlContent = streamReader.ReadToEnd();        }        catch        {            Response.Write("对不起出错了");        }        return strHtmlContent;    }}
原创粉丝点击