关于ASP转换成HTM的一段代码

由 Sheik 于 2008/03/13 下午 10:53 发布

  <%
  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.lastidea.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>"
  %>
  这是网上能搜到的转载最多的一段转换代码,但实际操作起来还是有些许困难,下面这段代码是鄙人从一位帅哥的空间上偶尔发现,小试了一下,哇靠,超爽,效果奇好,有兴趣的哥们不妨试试。(放在index.asp同一目录下,在IE中输入其地址,点击生成按钮,大功告成了就,哈哈……)
  <%
  filename="index.htm"
  webContent=request.form("body")
  if webContent<>"" then
  set fileObject = Server.CreateObject("Scripting.FileSystemObject")
  set fileOut = fileObject.CreateTextFile(server.mappath(filename))
  fileOut.writeline webContent
  fileOut.close
  set fileOut=nothing
  set fileObject=nothing
  end if
  %>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <script language="javascript">
  function closewin()
  {
  window.close();
  }
  </script>
  </head>
  <body>
  <center>
  文件可以成功生成! <a onclick="closewin()" href="#">关闭窗口</a>
  </center>
  </body>
  </html>
  showHTML.asp 文件:
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  </head>
  <body>
  <form action="createHTML.asp" method="post" >
  <textarea name="body" cols="120" rows="30">
  <!–#include file="index.asp"–>
  </textarea>
  <p/>
  <input type="submit" value="生成 index.htm文件">
  </form>
  </body>
  </html>

#广而告之:开微博,赢红包,还有无限充值卡等你拿,马上注册吧!
#好糠共享:史上第一个能安装ipa的ipa,安全快捷,超强体验!!

非常友情告示:本站所载内容均收集整理自网络,仅以研究交流为目的,供大家参考、学习,不存在任何商业目的与商业用途。
欢迎转载本文:http://hi.just4free.info/post/66.html
上一篇 >
下一篇 >

相关日志

酱油响应 (2人次)

  1. 哥们 说道:

    不行啊,也许我太笨,请教啊,盼回复

  2. hibqhome 说道:

    呃,俺也试试看……效果如何?

酱油感言

Advertisement

最近更新

谁人来过