將asp頁面轉換成htm頁面[轉]

文章來源:博客園

<%

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://www.sina.com.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地址)和dizhi(要保存的html地址)設置好就可以了,一般這兩個文件在同一個目錄,才能保證圖片或者css、js起作用。

希望對那些正在尋找asp->htm的朋友有用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章