asp的每天生成html

因为有个站是asp的所以看了一下,然后觉得asp打开有点慢,就想写一个生成静态的,就写了这个,可能不是很完美,有意见的请留言

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%

Function BytesToBstr(body,Cset) 
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 = Cset 
BytesToBstr = objstream.ReadText 
objstream.Close 
set objstream = nothing 
End Function 

Function getHTTPPage(url) 
On Error Resume Next 
dim http 
set http=Server.createobject("Microsoft.XMLHTTP") 
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then 
exit function 
end if 
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") 
set http=nothing 
If Err.number<>0 then 
Response.Write "<p align='center'><font color='red'><b>出错</b></font></p>" 
Err.Clear 
End If 
End Function 

Function getFileContents(strIncludeFile) '函数:读取包含文件内容
Dim objFSO,objText,strPage
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") '调用FSO对象
Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))
getFileContents = objText.ReadAll
objText.Close
Set objText = Nothing
Set objFSO = Nothing
End Function

yyyy=Year(date)
mm=Month(date)
dd=Day(date)

htmlss= "coach/index/"&yyyy&""&mm&""&dd&".html"

set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(server.mappath(htmlss)) then
    'fso.DeleteFile server.mappath("1.png"),true
    'response.write "<img src=img/111.jpg>"
    response.write getFileContents(htmlss)
	set fso=nothing
	response.end
else
%>
<html>
<head>
</head>
<body>
	<h1>hello world!</h1>
</body>
</html>
<%
	yyyy2=Year(date-1)
	mm2=Month(date-1)
	dd2=Day(date-1)
	htmlss2= "coach/index/"&yyyy2&""&mm2&""&dd2&".html"
	if fso.fileexists(server.mappath(htmlss2)) then
		fso.DeleteFile server.mappath(htmlss2),true
	end if
	
    'response.write htmlss
    wris=getHTTPPage("http://www.yiecho.com/index2.asp")
    Set CrFi=fso.CreateTextFile(server.mappath(htmlss),True) 
	CrFi.write(wris)
	set CrFi=nothing 
	set fso=nothing
end if
%>

asp的每天生成html:等您坐沙发呢!

发表评论

表情
还能输入210个字