Dynamic | static | page | page |
Some time ago There is an ASP page to perform slowly, the number of visitors, but not often modified, and lazy directly into static, every time to download from the server to change, had to think of ways to convert the ASP page into the HTM static page.
Have seen such an article before, but did not care too much, really want to use when it is difficult to find a suitable, so the online search for a long time to finally find the more appropriate code plus their own changes, as follows:
<%
Function getpage (URL)
' Get the contents of the file
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.webjx.com" ' address of the page to 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
' Address of the page 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)
Set crfi=nothing
Set fs=nothing
Response.Write "... <font color=red> update complete! </font> "
%>
Code is the simplest, directly saved into an ASP file can be, as long as the URL (to convert the ASP address) and Dizhi (to save the HTML address) set up on it, generally these two files in the same directory, in order to ensure that the picture or CSS, JS function.
Want to be useful to friends who are looking for an ASP-generated HTM.