原理:用ASP獲取動態頁面的html代碼後,再將這些html代碼寫成Html代碼。
<%
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
path=server.mappath("index.Html")
If Myfileobject.fileexists(path) Then '如果存在此文件,刪除之
MyfileObject.deletefile path
End If
Set MyTextFile=MyFileObject.CreateTextFile(path)
strurl="http://www.sina.com.cn/" '這裡可以換成其他動態頁面的地址。
strTmp = GetHTTPPage(trim(strurl))
MyTextFile.WriteLine(strTmp)
MytextFile.Close
response.write "完成任務"
%>
<%
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<p align='center'><font color='red'><b>服務器獲取文件內容出錯</b></font></p>"
Err.Clear
End If
End Function
Function BytesToBstr(body,Cset)
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 = Cset
BytesToBstr = obJStream.ReadText
obJStream.Close
set obJStream = nothing
End Function
%>