您现在的位置:网侠>技术开发>ASP教程>正文
正文

将asp页面转换成htm页面

文章来源:博客园 文章作者: 发布时间:2006-10-16 【字体:
收藏本文】 【推荐好友】 【进入博客】 【进入论坛

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

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

<%
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
字串9

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

字串1

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

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

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

字串1

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

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

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

字串6

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




上一篇:Microsoft VBscript运行时错误'800a000d'的解决方案  下一篇:玩PC蛋蛋,免费Q币等你来拿!
推荐新闻
     
 
邮箱:ewind@qq.com
建议您使用:1024*768以上分辩率浏览本站 如果你喜欢本站 请收藏本站 并推荐给你的朋友一起分享
免责声明:本站部分内容收集于网络,版权归原作者及出版社所有!如果您觉得侵犯了您的版权请来信告诉我们,我们会尽快删除其内容!