将asp页面转换成htm页面的方法

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

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

  1. <%
  2. Function GetPage(url) 
  3.  '获得文件内容
  4.  dim Retrieval
  5.  Set Retrieval = CreateObject("Microsoft.XMLHTTP"
  6.  With Retrieval 
  7.   .Open "Get", url, False ', "", "" 
  8.   .Send 
  9.   GetPage = BytesToBstr(.ResponseBody)
  10.  End With 
  11.  Set Retrieval = Nothing 
  12. End Function
  13. Function BytesToBstr(body)
  14.  dim objstream
  15.  set objstream = Server.CreateObject("adodb.stream")
  16.  objstream.Type = 1
  17.  objstream.Mode =3
  18.  objstream.Open
  19.  objstream.Write body
  20.  objstream.Position = 0
  21.  objstream.Type = 2
  22.  objstream.Charset = "GB2312"
  23.  BytesToBstr = objstream.ReadText 
  24.  objstream.Close
  25.  set objstream = nothing
  26. End Function
  27. on error resume next
  28. Url="http://www.sina.com.cn"'要读取的页面地址
  29. response.write "开始更新首页..."
  30. wstr = GetPage(Url)
  31. 'response.write(wstr)
  32. Set fs=Server.CreateObject("Scripting.FileSystemObject")
  33. 'if not MyFile.FolderExists(server.MapPath("/html/")) then 
  34. 'MyFile.CreateFolder(server.MapPath("/html/"))'
  35. 'end if
  36. '要存放的页面地址
  37. dizhi=server.MapPath("index.htm")
  38. If (fs.FileExists(dizhi)) Then
  39. fs.DeleteFile(dizhi)
  40. End If
  41. Set CrFi=fs.CreateTextFile(dizhi)
  42. Crfi.Writeline(wstr)
  43. set CrFi=nothing
  44. set fs=nothing
  45. response.write "...<font color=red>更新完成!</font>"
  46. %>

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

希望对那些正在寻找由asp生成htm的朋友有用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值