最简单asp生成静态方法

huang   发表时间:2009-01-15 11:05:38   分类:建站知识   浏览( )   评论( )   收藏日志
添加到网摘:

 asp简单生成静态方法:

 生成代码:

asp 代码
 
  1. <% 
  2. txtURL= strTemp&Request.ServerVariables("SERVER_NAME")"/q966.asp" 
  3. '要生成页面的地址q966.asp
  4. sText = getHTTPPage(txtURL)  
  5. 'response.Write(sText) 
  6. Set FileObject=Server.CreateObject("Scripting.FileSystemObject"
  7. filename="/q966.html" 
  8. '生成之后的名字q966.html
  9. Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立 
  10. openFile.writeline sText 
  11. Set OpenFile=nothing   
  12.  
  13. response.write "<script language=JavaScript>{window.alert('生成静态成功!');}</script>" 
  14.  
  15.     response.end 
  16. %>

要调用的函数:

asp 代码
 
  1. <%
  2. Server.ScriptTimeout=9999
  3.  
  4.  
  5.  
  6. '常用函数
  7. '1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
  8. function getHTTPPage(url)
  9. dim Http
  10. set Http=server.createobject("Microsoft.XMLHTTP")
  11. Http.open "GET",url,false
  12. http.setRequestHeader "If-Modified-Since","0"
  13. Http.send()
  14. if Http.readystate<>4 then 
  15. exit function
  16. end if
  17. getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
  18. set http=nothing
  19. if err.number<>0 then err.Clear 
  20. end function
  21.  
  22. '2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
  23. Function BytesToBstr(body,Cset)
  24. dim objstream
  25. set objstream = Server.CreateObject("adodb.stream")
  26. objstream.Type = 1
  27. objstream.Mode =3
  28. objstream.Open
  29. objstream.Write body
  30. objstream.Position = 0
  31. objstream.Type = 2
  32. objstream.Charset = Cset
  33. BytesToBstr = objstream.ReadText 
  34. objstream.Close
  35. set objstream = nothing
  36. End Function
  37.  
  38. If LCase(Request.ServerVariables("HTTPS")) = "off" Then
  39. strTemp = "http://" 
  40. Else
  41. strTemp = "https://"
  42. End If
  43.  
  44.  function makefilename(fname)
  45. fname = fname
  46. fname = replace(fname,"-","")
  47. fname = replace(fname," ","")
  48. fname = replace(fname,":","")
  49. fname = replace(fname,"PM","")
  50. fname = replace(fname,"AM","")
  51. fname = replace(fname,"上午","")
  52. fname = replace(fname,"下午","")
  53. makefilename = fname & ".html"
  54. end function
  55.  
  56. '保持数据格式不变的函数
  57. function HTMLEncode(fString)
  58. fString = replace(fString,">",">")
  59. fString = replace(fString,"<","<")
  60. fString = replace(fString,CHR(32)," ")
  61. fString = replace(fString,CHR(13),"")
  62. fString = replace(fString,CHR(10)&CHR(10),"<br>")
  63. fString = replace(fString ,CHR(10),"<br>")
  64. HTMLEncode = fString
  65. end function
  66.  
  67. %>

 

正在读取日志的评论数据,请稍后……
正在加载日志评论签写框,请稍后……
溜溜show会员登录
正在载入溜溜show会员登录...
溜溜show 日志归档
溜溜show 最新评论
{$SideComment}
溜溜show 最新留言
{$SideGB}
溜溜 阿里妈妈广告