ASP批量生成HTML
作者:wang 日期:2009-10-12
方法一:
<%
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值
<%
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值
评论: 0 | 引用: 0 | 查看次数: 2308
发表评论