2019/3/26 12:38:44
前段時間有(yǒu)個(gè)asp頁面執行(xíng)起來很慢(màn),訪問人(rén)數又(yòu)頗多,而且又(yòu)不經常修改,又(yòu)懶得直接做成靜态的(de),每次都(dōu)要從服務器(qì)下載來改,隻好想辦法把asp頁面轉化成htm靜态頁面了,以增加承載的(de)訪問人(rén)數和(hé)較少(shǎo)資源的(de)消耗。此代碼适合鑫冠提供的(de)獨立主機。
<%
Function GetPage(url)
'獲得文(wén)件(jiàn)内容
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://www.sina.com.cn"'要讀(dú)取的(de)頁面地(dì)址
response.write "開(kāi)始更新首頁..."
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
'要存放(fàng)的(de)頁面地(dì)址
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>"
%>
代碼算是最簡單的(de),直接保存成一個(gè)asp文(wén)件(jiàn)即可(kě),隻要把URL(要轉化的(de)asp地(dì)址)和(hé)地(dì)址(要保存的(de)html地(dì)址)設置好就可(kě)以了,一般這兩個(gè)文(wén)件(jiàn)在同一個(gè)目錄,才能(néng)保證圖片或者css、js起作用(yòng)。
深圳市南山區南山街(jiē)道南海(hǎi)大(dà)道西(xī)桂廟路(lù)北陽光(guāng)華藝大(dà)廈1棟4F、4G-04
咨詢電話(huà):136 8237 6272
大(dà)客戶咨詢:139 0290 5075
業(yè)務QQ:195006118
技術(shù)QQ:179981967