将asp页面转换成htm页面

『本文地址:http://v2.djasp.net/Static/ns/2041.stm

前段时间有个asp页面执行起来很慢,访问人数又颇多,而且又不经常修改,又懒得直接做成静态的,每次都要从服务器下载来改,只好想办法把asp页面转化成htm静态页面了。。。

以前就曾经看到这样的文章,不过没太在意,真正想用的时候很难找到一个合适的,于是在网上搜索了半天终于找到比较合适的代码再加上自己的修改,如下:

<%
Function GetPage(url)
 '获得文件内容
 dim Retrieval
 Set Retrieval = CreateObject("Microsoft.XMLHTTP")
 With Retrieval
  .Open "Get", url, False ', "", ""
  .Send
  GetPage = BytesToBstr(.ResponseBody)
 End With
 Set Retrieval = Nothing
End Function

Function BytesToBstr(body)
 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 = "GB2312"
 BytesToBstr = objstream.ReadText
 objstream.Close
 set objstream = nothing
End Function

on error resume next
Url="http://www.djasp.net"'要读取的页面地址
response.write "开始更新首页..."
wstr = GetPage(Url)

'response.write(wstr)
Set fs=Server.CreateObject("Scripting.FileSystemObject")

'if not MyFile.FolderExists(server.MapPath("/html/")) then
'MyFile.CreateFolder(server.MapPath("/html/"))'
'end if

'要存放的页面地址
dizhi=server.MapPath("index.htm")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If

Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>更新完成!</font>"
%>


代码算是最简单的,直接保存成一个asp文件即可,只要把URL(要转化的asp地址)和dizhi(要保存的html地址)设置好就可以了,一般这两个文件在同一个目录,才能保证图片或者CSS、js起作用。

希望对那些正在寻找asp->htm的朋友有用。

本文统计
上一篇: 用javascript获得地址栏参数及应用范…
下一篇: 修改asp代码防止被杀毒软件误删
文章类别:常见问题经典收藏
最后更新:2006-12-9 21:46:37
浏览次数:
本栏最新文章
本栏推荐文章
随机酷站设计秀
网站导航 |走进点击 |点击作品 |服务项目 |联系我们 |设为首页 |加入收藏 |在线留言
点击设计
点击设计© Version: 2.3 WEB执行标准:W3C XHTML 1.1 / CSS 2.0 / Ajax
本站全面兼容 IE、FireFox、Netscape、Opera 等内核的浏览器
版权所有:点击设计 www.djasp.Net E-mail:djasp@qq.com
全程开发:秋水天子(Folier) QQ:39886616
版权所有:点击设计 www.djasp.net
浙ICP备05074939号