ASP批量生成HTML

方法一:


<%
Dim weburl
sql = "Select top 10 zc_id from zc_news order by zc_id desc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.OPEN sql,db,1,3
do while not rs.eof
weburl=""
body=getHTTPPage(weburl)

Set fso = CreateObject("Scripting.FileSystemObject")
File=Server.MapPath("/20085/"&rs("id")&".htm")
Set txt=fso.OpenTextFile(File,8,True)
txt.WriteLine weburl
txt.Close
txt.fso

rs.movenext
loop
rs.close
set rs=nothing
%>

方法二:



<%
sql = "Select * FROM "表名" order by id desc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.OPEN sql,conn,1,3
do while not rs.eof
%>
<%
url = "http://页面地址.asp?id="&rs("id")&""
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET",url,false
Http.send()
set objStream = Server.CreateObject("ADODB.Stream")
objStream.type = 1
objStream.open
objstream.write http.responseBody
objstream.saveToFile server.mappath("html/"&rs("id")&".htm"),2
objstream.close
rs.movenext
loop
rs.close
set rs=nothing
Response.Write "操作成功!"
%>


方法三:


<%
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
%>  
<%
strSQL="Select ID From news order by ID Desc"
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.open strSQL,conn,1,1
do while not rs.eof                

on error resume next
Url="http://www.maiyaocai.net/maiyaocai/show.asp?"&trim(rs("ID"))&""'要读取的页面地址
response.write "开始更新show.asp?/"&trim(rs("ID"))&".html"

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("show"&trim(rs("ID"))&".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 "...show"&trim(rs("ID"))&".htm更新完成!
"

rs.movenext    
loop
%>


需要修改的部分:

1.数据库路径(在conn.asp中)

2.要读取的页面地址 URL值

3.要存放的页面地址 dizhi值


上一篇: ASP+模板生成静态HTML
下一篇: ASP防止注入的代码
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 2308
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 300 字 | UBB代码 开启 | [img]标签 关闭