网站生成HTML静态页好处太多了,利于SEO优化排名,提升网站打开速度等等,青岛星网下面跟大家分享:ASP利用XMLHTTP生成html静态页范例,大家可以根据这个范例自行扩展哦。
<% '作者:青岛星网 www.qdxw.net '利用XMLHTTP生成HTML function getHTTPPage(url) dim Http set Http=server.createobject("MSXML2.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 sText = getHTTPPage("http://www.qdxw.net") Set FileObject=Server.CreateObject("Scripting.FileSystemObject") filename="a.htm" '这里是你要生成的HTML名字 Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立 openFile.writeline(sText) Set OpenFile=nothing response.Write("HTML生成成功。") %>
大家可以复制代码保存成为一个asp文件,自己运行测试下。