Some time ago, there was an ASP page that was very slow to execute, had a lot of visitors, and was not modified often. I was too lazy to make it static directly. I had to download it from the server every time to change it, so I had to find a way to convert the ASP page into HTM. Static page. . .
I have seen articles like this before, but I didn’t pay much attention to it. It was difficult to find a suitable one when I really wanted to use it, so I searched the Internet for a long time and finally found a more suitable code and added my own modifications, as follows:
<%
Function GetPage(url)
'Get file content
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"' The page address to be read
response.write "Start updating the home page..."
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
'The page address to be stored
dizhi=server.MapPath("index.htm")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If
Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
setCrFi=nothing
set fs=nothing
response.write "...<font color=red>Update completed!</font>"
%>
The code is the simplest. It can be saved directly into an asp file. Just set the URL (the asp address to be converted) and dizhi (the html address to be saved). Generally, these two files are in the same directory. Only then can we ensure that images, css, and js work.
I hope it will be useful to those friends who are looking for asp->htm.