欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp定时生成静态HTML的代码

程序员文章站 2023-01-24 20:06:59
复制代码 代码如下: <% '判断是否要生成新的html if application("cache_asptohtml_date")="" then applica...

复制代码 代码如下:

<%
'判断是否要生成新的html
if application("cache_asptohtml_date")="" then
application.lock
application("cache_asptohtml_date")=now()
application.unlock
call asptohtml
response.redirect("index.html")
end if
if datediff("s", application("cache_asptohtml_date"),now)> 100 then '比较上次更新时间与当前时间相差多少秒
application.lock
application("cache_asptohtml_date")=now()
application.unlock
call asptohtml
response.redirect("index.html")
else
response.redirect("index.html")
end if

'获取当前目录!
function getpath
if request.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")
end if
getpath=left(userurl,instrrev(userurl,"/"))
end function

sub asptohtml
'----------------------------------------------------------
'使用xmlhttp生成静态首页的代码
'curl 为你的首页地址,确保你的空间支持fso
'-----------------------------------------------------------
dim read,curl,content
curl=getpath&"home.asp"
read=gethttppage(curl)
if read<>"" then
content=read
set fso = server.createobject("scripting.filesystemobject")
filen=server.mappath("index.html")
set site_config=fso.createtextfile(filen,true, false)
site_config.write content
site_config.close
set fso = nothing
end if
end sub
function gethttppage(url)
dim http
set http=server.createobject("microsoft.xmlhttp")
http.open "get",url,false
http.send()
if http.readystate<>4 then
exit function
end if
gethttppage=bytestobstr(http.responsebody,"gb2312")
set http=nothing
if err.number<>0 then err.clear
end function

function bytestobstr(body,cset)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
%>

asp定时生成静态页(html)2
复制代码 代码如下:

<%
set fs=server.createobject("scripting.filesystemobject")
file=server.mappath("time.txt")
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
times=txt.readline
else
response.write "<br /><!--有没有发现time.txt 开始生成!-->"
htmlpage = "time.txt" '//生成的html文件名
template = now()
set fso = server.createobject ("scripting.filesystemobject")
set fileout = fso.createtextfile(server.mappath (htmlpage))
fileout.writeline template
fileout.close
set fso = nothing
end if


if datediff("s",times,now()) > 3600 then '//上次更新到现在的时间 大于 3600秒 则 更新
response.write "<br /><!--时间过了开始更新-->"

code = "这里是需要生成的html代码" '//如何得到代码的方式有很多

'//用fso生成html页面
htmlpage = "index.html" '//生成的html文件名
template = code
set fso = server.createobject ("scripting.filesystemobject")
set fileout = fso.createtextfile(server.mappath (htmlpage))
fileout.writeline template
fileout.close
set fso = nothing

'//用fso生成time.txt文件
htmlpage = "time.txt" '//生成的html文件名
template = now()
set fso = server.createobject ("scripting.filesystemobject")
set fileout = fso.createtextfile(server.mappath (htmlpage))
fileout.writeline template
fileout.close
set fso = nothing

else

response.write "<br /><!-- 已经过去"&datediff("s",times,now())&"秒!-->"

end if
%>