<%
Function MakeHtml(strURL,strTo)
on error resume next
response.write "开始生成静态页面..."
strHtml = GetPage(strURL)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'要存放的页面地址
strAddress=server.MapPath(strTo)
'如果文件存在则删除旧文件
If (fs.FileExists(strAddress)) Then fs.DeleteFile(strAddress)
Set mHtml=fs.CreateTextFile(strAddress)
mHtml.Writeline(strHtml)
set mHtml=nothing
set fs=nothing
response.write "...<font color=red>生成静态页面<"&strTo&">成功!</font>"
End Function
'######获取要生成动态页地址######
Function GetPage(url)
'获得文件内容
dim Retrieval
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False,"", ""
.Send
GetPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
'######转换字符######
Function BytesToBstr(body)
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 = "GBK"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
保存为MakeHtml.inc.asp
使用方法:
在要实现生成静态功能的页面头部添加
<!--#include file="<你存放的路径>/makehtml.inc.asp"-->
在需要调用生成静态页面的地方添加
MakeHtml “http://localhost/index.asp","/index.html"
上面的路径换成你自己的,这样即可无模板生成静态页面。不过这种方法比较耗资源,生成速度慢,但是简单易上手。