[转载]asp生成静态网页htm简单方法
时间:2006-09-06 来源:a010
asp生成静态网页htm简单方法
先做2个文件:htm.asp 和 htm123.asp
htm.asp 是生成index.htm
htm123.asp 是生成index1.htm index2.htm index3.htm
可以一起用,也可以单个用!
使用条件:1,网站首页文件为:index.asp
2,生成文件格式为:index.htm
3,网站文档顺序为: index.htm,index.asp
不对的请自行修改。
使用方法:
1,把htm.asp或htm123.asp(根据使用要求)拷贝到网站根目录。
2,运行文件:htm.asp或htm123.asp
看到如下内容,表示生成成功!
成功生成文件:
x:/xxx/xxx\xxx\Index.htm
注:代码很简单,觉得功能不够请自行修改源文件!
以下是htm.asp的代码,复制到记事本里存为:htm.asp
<%
dim strUrl,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
Html_Temp = Html_Temp&"<LI>"
FileName = "Index"&".htm"
FilePath = Server.MapPath("/")&"\"&FileName
Html_Temp = Html_Temp&FilePath&"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/index.asp"
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.createObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile FilePath,2
objAdoStream.Close()
Html_Temp = Html_Temp&"<UL>"
%>
<%
Response.Write ( "成功生成文件:" )
Response.Write ( "<BR>" )
Response.Write Html_Temp
%>
以下是htm123.asp的代码,复制到记事本里存为:htm123.asp
<%
dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp&"<LI>"
Item_Classid = i
FileName = "Index"&Item_Classid&".htm"
FilePath = Server.MapPath("/")&"\"&FileName
Html_Temp = Html_Temp&FilePath&"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/index.asp"
Do_Url = Do_Url&"?Item_Classid="&Item_Classid
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.createObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile FilePath,2
objAdoStream.Close()
Next
Html_Temp = Html_Temp&"<UL>"
%>
<%
Response.Write ( "成功生成文件:" )
Response.Write ( "<BR>" )
Response.Write Html_Temp
%>
先做2个文件:htm.asp 和 htm123.asp
htm.asp 是生成index.htm
htm123.asp 是生成index1.htm index2.htm index3.htm
可以一起用,也可以单个用!
使用条件:1,网站首页文件为:index.asp
2,生成文件格式为:index.htm
3,网站文档顺序为: index.htm,index.asp
不对的请自行修改。
使用方法:
1,把htm.asp或htm123.asp(根据使用要求)拷贝到网站根目录。
2,运行文件:htm.asp或htm123.asp
看到如下内容,表示生成成功!
成功生成文件:
x:/xxx/xxx\xxx\Index.htm
注:代码很简单,觉得功能不够请自行修改源文件!
以下是htm.asp的代码,复制到记事本里存为:htm.asp
<%
dim strUrl,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
Html_Temp = Html_Temp&"<LI>"
FileName = "Index"&".htm"
FilePath = Server.MapPath("/")&"\"&FileName
Html_Temp = Html_Temp&FilePath&"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/index.asp"
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.createObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile FilePath,2
objAdoStream.Close()
Html_Temp = Html_Temp&"<UL>"
%>
<%
Response.Write ( "成功生成文件:" )
Response.Write ( "<BR>" )
Response.Write Html_Temp
%>
以下是htm123.asp的代码,复制到记事本里存为:htm123.asp
<%
dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp&"<LI>"
Item_Classid = i
FileName = "Index"&Item_Classid&".htm"
FilePath = Server.MapPath("/")&"\"&FileName
Html_Temp = Html_Temp&FilePath&"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/index.asp"
Do_Url = Do_Url&"?Item_Classid="&Item_Classid
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.createObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile FilePath,2
objAdoStream.Close()
Next
Html_Temp = Html_Temp&"<UL>"
%>
<%
Response.Write ( "成功生成文件:" )
Response.Write ( "<BR>" )
Response.Write Html_Temp
%>
再来一简单的ASP生成静态网页的方法
将以下代码另存为mk.asp 运行即可生成index.htm
<%url = "http://网站网址/index.asp"
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET",url,false
Http.send()
set objStream = Server.CreateObject("ADODB.Stream")
objStream.type = 1
objStream.open
objstream.write http.responseBody
objstream.saveToFile server.mappath("index.htm"),2
objstream.close
Response.Write "生成静态网页成功!<a href=index.htm>浏览生成的网页</a>"%>
相关阅读 更多 +