前段時間有個asp頁面執(zhí)行起來很慢,訪問人數又頗多,而且又不經常修改,又懶得直接做成靜態(tài)的,每次都要從服務器下載來改,只好想辦法把asp頁面轉化成htm靜態(tài)頁面了,以增加承載的訪問人數和較少資源的消耗。此代碼適合萬網提供的獨立主機。
<%
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://m.2m8n56k.cn"'要讀取的頁面地址
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>"
%>
代碼算是最簡單的,直接保存成一個asp文件即可,只要把URL(要轉化的asp地址)和地址(要保存的html地址)設置好就可以了,一般這兩個文件在同一個目錄,才能保證圖片或者css、js起作用。
當前標題:將asp頁面轉換成htm頁面,減少資源的消耗
文章網址:http://m.2m8n56k.cn/news21/292421.html
成都網站建設公司_創(chuàng)新互聯,為您提供移動網站建設、企業(yè)網站制作、虛擬主機、網頁設計公司、網站制作、App設計
廣告
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源:
創(chuàng)新互聯