最近网站涉及到生成HTML静态网页,没办法找了很多资料,不过也都大同小异,最后采用了如下代码来生成静态文章!该代码主要原理是通过浏览器传送变量,如:http://www.3zha.com/news.asp?id=7,代码中:if SaveFile("/news_news/"&id&".html","http://www.3zha.com/news.asp?id="&id&"") then 中"/news_news/"&id&".html",是你生成的文件和路径。http://127.0.0.1/news.asp?id="&id&""是asp的路径可以自己设置修改,其中 "&id&" 是读取浏览器的变量,网站网址改成自己的。使用方法,给你的文章列表添加一个连接,如 http://127.0.0.1/html.asp?id=7 ,7这个变量相信大家会调用吧,这样就能在/news_news目录下生成按照id排列的html文章了!可以到这里看效果:http://www.3zha.com/news.asp,http://www.3zha.com/news_news/7.html以下是主要代码,把要改的代码改成自己的,保存成html.asp文件!
以下是引用片段:
<%
Dim id
id = Request("id")
%>
<%
if SaveFile( "/news_news/"&id&".html","http://www.3zha.com/news.asp?id="&id&"" ) then
response.Write "<script language=javascript>alert(’生成静态页面成功!’);history.go(-1);</script>"
else
Response.write "没有生成!"
end if
function SaveFile(LocalFileName,RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microso" & "ft.XM" & "LHTTP") ’//把单词拆开防止杀毒软件误杀
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Ado" & "db.Str" & "eam") ’//把单词拆开防止杀毒软件误杀
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
if err <> 0 then
SaveFile = false
err.clear
else
SaveFile = true
end if
End function
%>
评论前必须登录!
注册