<%
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"
生成静态页面方法(1)ASP篇
最新推荐文章于 2021-09-12 17:11:10 发布