您当前的位置: 首页 > 网站编程 > ASP教程 > asp定时生成静态HTML的代码

asp定时生成静态HTML的代码

作者:不详 来源:网络 发布时间: 2010-08-15 21:37 点击:
代码如下: % '判断是否要生成新的HTML ifApplication(cache_asptohtml_date)=then Application.Lock Application(cache_asptohtml_date)=now() Application.Unlock CallaspTohtml Response.Redirect(index.html) endif ifDateDiff(s,Application(cache_asptohtml_date)

asp定时生成静态HTML的代码

  代码如下:
  
  <%
  '判断是否要生成新的HTML
  ifApplication("cache_asptohtml_date")=""then
  Application.Lock
  Application("cache_asptohtml_date")=now()
  Application.Unlock
  CallaspTohtml
  Response.Redirect("index.html")
  endif
  ifDateDiff("s",Application("cache_asptohtml_date"),Now)>100then'比较上次更新时间与当前时间相差多少秒
  Application.Lock
  Application("cache_asptohtml_date")=now()
  Application.UnLock
  CallaspTohtml
  Response.Redirect("index.html")
  Else
  Response.Redirect("index.html")
  Endif
  
  '获取当前目录!
  functiongetpath
  ifRequest.ServerVariables("SERVER_PORT")<>"80"then
  UserUrl="http://"&Request.ServerVariables("SERVER_NAME")&":"&Request.ServerVariables("SERVER_PORT")&Request.ServerVariables("URL")
  else
  UserUrl="http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("URL")
  endif
  getpath=left(UserUrl,InstrRev(UserUrl,"/"))
  endfunction
  
  subaspTohtml
  '----------------------------------------------------------
  '使用XMLHTTP生成静态首页的代码
  'Curl为你的首页地址,确保你的空间支持FSO
  '-----------------------------------------------------------
  dimread,Curl,content
  Curl=getpath&"home.asp"
  read=getHTTPPage(Curl)
  ifread<>""then
  content=read
  SetFso=Server.CreateObject("Scripting.FileSystemObject")
  Filen=Server.MapPath("index.html")
  SetSite_Config=FSO.CreateTextFile(Filen,true,False)
  Site_Config.Writecontent
  Site_Config.Close
  SetFso=Nothing
  endif
  Endsub
  FunctiongetHTTPPage(url)
  dimhttp
  sethttp=Server.createobject("Microsoft.XMLHTTP")
  Http.open"GET",url,false
  Http.send()
  ifHttp.readystate<>4then
  exitfunction
  endif
  getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
  sethttp=nothing
  iferr.number<>0thenerr.Clear
  EndFunction
  
  FunctionBytesToBstr(body,Cset)
  dimobjstream
  setobjstream=Server.CreateObject("adodb.stream")
  objstream.Type=1
  objstream.Mode=3
  objstream.Open
  objstream.Writebody
  objstream.Position=0
  objstream.Type=2
  objstream.Charset=Cset
  BytesToBstr=objstream.ReadText
  objstream.Close
  setobjstream=nothing
  EndFunction
  %>
  
  
  ASP定时生成静态页(HTML)2
  
  复制代码代码如下:
  
  <%
  setfs=server.createobject("scripting.filesystemobject")
  file=server.mappath("time.txt")
  settxt=fs.opentextfile(file,1,true)
  ifnottxt.atendofstreamthen
  times=txt.ReadLine
  Else
  response.write"<br/><!--有没有发现time.txt开始生成!-->"
  HtmlPage="time.txt"'//生成的HTML文件名
  Template=NOW()
  SetFSO=Server.CreateObject("Scripting.FileSystemObject")
  SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
  FileOut.WriteLineTemplate
  FileOut.Close
  SetFSO=Nothing
  endIf
  
  
  Ifdatediff("s",times,NOW())>3600Then'//上次更新到现在的时间大于3600秒则更新
  response.write"<br/><!--时间过了开始更新-->"
  
  code="这里是需要生成的html代码"'//如何得到代码的方式有很多
  
  '//用FSO生成HTML页面
  HtmlPage="index.html"'//生成的HTML文件名
  Template=code
  SetFSO=Server.CreateObject("Scripting.FileSystemObject")
  SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
  FileOut.WriteLineTemplate
  FileOut.Close
  SetFSO=Nothing
  
  '//用FSO生成time.txt文件
  HtmlPage="time.txt"'//生成的HTML文件名
  Template=NOW()
  SetFSO=Server.CreateObject("Scripting.FileSystemObject")
  SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
  FileOut.WriteLineTemplate
  FileOut.Close
  SetFSO=Nothing
  
  Else
  
  response.write"<br/><!--已经过去"&datediff("s",times,NOW())&"秒!-->"
  
  EndIf
  %>

分享到:
本文"asp定时生成静态HTML的代码"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4