asp输出到html
作者:admin 日期:2011-01-29
其实就是用了一个组件msxml2.serverXMLHTTP
适合于少量页面的静态化,因为这个需要消耗一些时间,页面数量过多的话,会超时的。基本上一次生成30个页面左右就差不多了。废话不说了,直接上代码。
<%
function getURL(url)
dim xml
set xml=server.CreateObject("msxml2.serverXMLHTTP")
with xml
.Open "GET",url,false
.Send
if .readyState = 4 then
getURL=.ResponseBody
else
getURL="Fail"
end if
end with
set xml=nothing
end function
function getCharset(byval s)
s=StringFromBytes(s,"utf-8")
set reg=new RegExp
with reg
.pattern="charset=.+?"""
.ignorecase=true
.global=false
set c=.execute(s)
d=c(0).Value
getCharset=mid(d,9,len(d)-9)
end with
set reg=nothing
end function
Function StringFromBytes(bytes , cSet)
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write bytes
.Position = 0
.Type = 2
.Charset = cSet
StringFromBytes = .ReadText()
.Close
End With
End Function
function saveToFile(byval s,byval filename)
filename=server.MapPath("./"&filename)
cset=getCharset(s)
set http=server.CreateObject("adodb.stream")
with http
.mode=3
.type=1
.open
.write s
.position=0
.type=2
.charset=cset
.savetofile filename,2
.close
end with
set http=nothing
end function
function getHtml(xURL,filename)
dim html
html=getURL(xURL)
savetofile html,filename
end function
getHtml "http://localhost/article.asp?id=498","498.html"
%>
最后一句是生成id为498的页面。是用来测试的。大家只需要调用gethtml这个函数即可。