QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

asp基础

asp生成静态页面方法

 admin  2013-08-18 22:51:00

原理:用asp获取动态页面的html代码后,再将这些html代码写成html代码。
 

  1. <%  
  2. Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")  
  3. path=server.mappath("index.html")  
  4. If Myfileobject.fileexists(path) Then '如果存在此文件,删除之  
  5. MyfileObject.deletefile path  
  6. End If  
  7. Set MyTextFile=MyFileObject.CreateTextFile(path)  
  8. strurl="http://www.sina.com.cn/" '这里可以换成其他动态页面的地址。  
  9. strTmp = GetHTTPPage(trim(strurl))  
  10.  
  11. MyTextFile.WriteLine(strTmp)  
  12.  
  13. MytextFile.Close  
  14. response.write "完成任务"  
  15. %> 
  16.  
  17. <%  
  18. Function getHTTPPage(url)   
  19. On Error Resume Next  
  20. dim http   
  21. set http=Server.createobject("Microsoft.XMLHTTP")   
  22. Http.open "GET",url,false   
  23. Http.send()   
  24. if Http.readystate<>4 then  
  25. exit function   
  26. end if   
  27. getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")  
  28. set http=nothing 
  29. If Err.number<>0 then   
  30. Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"   
  31. Err.Clear  
  32. End If   
  33. End Function  
  34.  
  35. Function BytesToBstr(body,Cset)  
  36. dim objstream  
  37. set objstream = Server.CreateObject("adodb.stream")  
  38. objstream.Type = 1 
  39. objstream.Mode =3 
  40. objstream.Open  
  41. objstream.Write body  
  42. objstream.Position = 0 
  43. objstream.Type = 2 
  44. objstream.Charset = Cset 
  45. BytesToBstr = objstream.ReadText   
  46. objstream.Close  
  47. set objstream = nothing 
  48. End Function  
  49. %> 

 

¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《asp生成静态页面方法》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/html/asp/167.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有0条评论
点击图片更换

添加微信好友

添加微信好友

微信小程序

百度小程序