简单实用的生成静态页方法
在制作网站,我们一般在许多时候都需要把网页生成静态,下面发一个简单的生成静态的方法。不属原创!是收集整理的。声时:空间必须要支持FSO组件
Function HtmlSave(Url,FileSavePath)
Dim Fso,Str
HtmlSave=false
Str=GetHttpPage(Url)
If Str="" Then Exit Function
Set Fso = Server.Createobject("Scripting.FileSystemObject")
Set Fso = Fso.CreateTextFile(Server.mappath(FileSavePath))
Fso.Write Str
Fso.Close:Set Fso=NoThing
HtmlSave=True
End Function
'==================================================
'函数名:GetHttpPage
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址
'==================================================
Function GetHttpPage(HttpUrl)
dim http
Set http=server.createobject("Msxml2.XMLHTTP")
Http.open "GET",HttpUrl,false
On Error Resume Next
Http.send()
If Http.readystate<>4 Then Exit Function
GetHttpPage=BytesToBstr(Http.ResponseBody,"GB2312")
If InStr(Lcase(getHTTPPage), "charset=utf-8") Then getHTTPPage=Http.responseText
Set http=nothing
if err.number<>0 then err.Clear
End Function
'==================================================
'函数名:BytesToBstr
'作 用:将获取的源码转换为中文
'参 数:Body ------要转换的变量
'参 数:Cset ------要转换的类型
'==================================================
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
'如果是首页要生成静态:
if HtmlSave("http://192.168.1.10/Index.asp",http://192.168.1.10/Index.html")=True then
response.write "生成成功"
else
response.write "生成失败"
end if
[[it] 本帖最后由 天涯听雨 于 2008-6-23 10:15 编辑 [/it]]
[[it] 本帖最后由 天涯听雨 于 2008-6-23 10:16 编辑 [/it]]