1.使用fso生成
<%
使用fso生成
set fs = createobject("scripting.filesystemobject")
newfile=server.mappath("ud03/fso.htm")
新建一文件fso.htm,若该文件已存在,则覆盖它
set a = fs.createtextfile(newfile, true)
response.write"新文件已建立!"
a.close
file=server.mappath("ud03/fso.htm")
set txt=fs.opentextfile(file,8,true) 打开成可以在结尾写入数据的文件
data1="这句话是使用writeline方法写入的。!<br>"
txt.writeline data1
data2="这句话是使用write方法写入的。<br>"
txt.write data2
txt.close
%>

 


2.使用xmlhttp生成
<%
使用xmlhttp生成
set xml = server.createobject("microsoft.xmlhttp")
把下面的地址替换成你的首页的文件地址,一定要用http://开头的绝对路径,不能写相对路径
xml.open "get", " ****(抓取页面) ", false
xml.send 
bodytext=xml.responsebody
bodytext=bytestobstr(bodytext,"gb2312")
set xml = nothing
dim fso, myfile 
set fso = createobject("scripting.filesystemobject")
set myfile= fso.createtextfile(server.mappath("index.htm"), true) 生成的html的文件名
myfile.writeline(bodytext)
myfile.close

使用adodb.stream处理二进制数据
function bytestobstr(strbody,codebase)
   dim objstream
   set objstream = server.createobject("adodb.stream")
   objstream.type = 1
   objstream.mode =3
   objstream.open
   objstream.write strbody
   objstream.position = 0
   objstream.type = 2
   objstream.charset = codebase
   bytestobstr = objstream.readtext 
   objstream.close
   set objstream = nothing
end function
%>

 

 

3.使用xmlhttp批量生成
<%
使用xmlhttp批量生成
dim strurl,item_classid,id,filename,filepath,do_url,html_temp
html_temp="<ul>"
for i=1 to 30 需要生成的id:1到30
html_temp = html_temp&"<li>"
item_classid = i
filename = "archives_"&item_classid&".htm" 生成的html文件名
filepath = server.mappath("/")&"\"&filename
html_temp = html_temp&filepath&"</li>"
do_url = " ****(抓取页面) " web路径
do_url = do_url&"?p="&item_classid web路径之后的id
strurl = do_url
dim objxmlhttp
set objxmlhttp = server.createobject("microsoft.xmlhttp")
objxmlhttp.open "get",strurl,false
objxmlhttp.send()
dim binfiledata
binfiledata = objxmlhttp.responsebody
dim objadostream
set objadostream = server.createobject("adodb.stream")
objadostream.type = 1
objadostream.open()
objadostream.write(binfiledata)
objadostream.savetofile filepath,2 
objadostream.close()
next
html_temp = html_temp&"<ul>"
%>
<%
response.write ( "成功生成文件:" )
response.write ( "<br>" )
response.write html_temp
%>

 


4.自动按模板生成网站首页
<%
response.expires = 0 
response.expiresabsolute = now() - 1 
response.addheader "pragma", "no-cache" 
response.addheader "cache-control", "private" 
response.cachecontrol = "no-cache" 
response.buffer = true 
response.clear
server.scripttimeout=999999999
on error resume next 
***************************************************************
*                        定义 从模板从读取首页 函数
* 说明:模板文件名为:index_template.asp
***************************************************************
function getpage(url) 
        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

***************************************************************
* 生页首页,文件名为:default.htm
***************************************************************
dim tstr
tstr = getpage(" ****(抓取页面) ")
set fso = server.createobject("scripting.filesystemobject")
set fout = fso.createtextfile(server.mappath(".")&"/default.htm")
fout.write tstr
fout.close
   response.write"<script>alert(""生成首页成功!\n\n文件名为:default.htm"");location.href= ****(返回页面) </script>"
   response.end
%>

 


5.将asp页面转换成htm页面
<%
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
on error resume next
url="  *****(抓取页面) "  要读取的页面地址
response.write "开始更新首页..."
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("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>更新完成!</font>"
%>

 


6.自己经常用的
<%
function gethttpxml()
set http = server.createobject("msxml2.serverxmlhttp")
  dim lresolve,lconnect,lsend,lreceive
  lresolve = 5*1000
  lconnect = 5*1000
  lsend = 15*1000
  lreceive = 15*1000
  http.settimeouts lresolve,lconnect,lsend,lreceive
  http.open "post"," ******(抓取页面) "," false 抓取需要生成html的页面
  http.send()
  if http.readystate =1 then str1=timer()
  if http.readystate =4 then str2=timer()
  if http.readystate <> 4 then
  exit function
  end if
  if http.readystate =0 then str1=timer()
  gethttpxml=bytestobstr(http.responsebody,"utf-8")
  gethttpxml=http.responsebody
  gethttpxml=formatnumber((str2-str1)/1000,3)
  if err.number<>0 then err.clear
end function

生成文件
function savetofile()
    dim objstream
    on error resume next
    set objstream = server.createobject("adodb.stream")
    if err.number=-2147221005 then
        response.write "<div align=center>非常遗憾,您的主机不支持adodb.stream,不能使用本程序</div>"
        err.clear
        response.end
    end if
    with objstream
        .type = 1
        .open
        .charset = "utf-8"
        .write gethttpxml
        .savetofile server.mappath("index.html"),2
        .close
    end with
    set objstream = nothing
end function

call savetofile()
%>