把指定网页改成HTM页(ASP代码实现方式)
以下代码是把指定网页改成HTM页(ASP代码实现方式),主要用到XMLHTTP,Stream,FSO组件来实现生成静态HTM的功能
<%
Function GetWebPage(url)'取得目标网页的源代码的功能函数
dim Obtain
Set Obtain = CreateObject("Microsoft.XMLHTTP")
With Obtain
.Open "Get", url, False '', "", ""
.Send
GetWebPage = BytesToBstr(.ResponseBody)
End With
Set Obtain = Nothing
End Function
Function BytesToBstr(body)'将获取的源码转换为中文
dim objstream
set objstream = Server.CreateObject("adodb.stream")'主要用到了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.auuo.com/"'远程调用例子,这里可以是index.asp或default.php文件都可以,只要输入网页网址就可以
response.write "开始更新首页..."
webstr = GetWebPage(Url)
Set htmlfso=Server.CreateObject("Scripting.FileSystemObject") '设置htmlfso以实现对htm的写入
If (htmlfso.FileExists(server.MapPath("./")&"\index.htm")) Then'如果有已有htm页则删除它,以方便接下来从新写入新建HTM
htmlfso.DeleteFile(server.MapPath("./")&"\index.htm")
End If
Set CreatFile=htmlfso.CreateTextFile(server.MapPath("./")&"\index.htm")'在当前目前下,建立一个index.htm文件
CreatFile.Writeline(webstr)
set CreatFile=nothing
set htmlfso=nothing
response.write "...<font color=red>生成更新Htm页完成!</font>"
%>