资源描述:
《关于asp程序生成静态页(asp转html)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、关于asp程序生成静态页(asp转html)--------------------------------------------------------------------------------网上这类的文章很多,大多数都是转载的,无非是两种:第一种:利用模板生成html文件;第二种:利用xmlhttp访问目标程序并保存成html第一种的麻烦之处在于要制作模板,做大型项目还好,小项目的话,灵活性就不足了;第二种有一个很大的缺陷:生成的静态页里的链接还是指向asp程序页面,光生成首页还好,要做到整
2、站的话,麻烦更大;我使用的是第二种方法,不过,我加了链接的替换,使生成的html页面保持互通。程序如下:<%server.scripttimeout=300'onerrorresumenextdimasp2html_langasp2html_lang="gb2312"functionasp2html_cpath(str)'过滤路径str=replace(str,"","")str=replace(str,":","")str=replace(str,"*","")str=replace(str,"?",
3、"")str=replace(str,"<","")str=replace(str,">","")str=replace(str,"
4、","")str=replace(str,chr(34),"")str=replace(str,"//","/")asp2html_cpath=strendfunctionfunctionasp2html_b2s(str)'转换二进制数据为文本dimostreamsetostream=server.createobject("adodb.stream")ostream.ty
5、pe=1ostream.mode=3ostream.openostream.writestrostream.position=0ostream.type=2ostream.charset=asp2html_langasp2html_b2s=ostream.readtextostream.closesetostream=nothingendfunctionfunctionasp2html_gettag(str)'获取所有链接dimr,matches,match,tmpurl,start,overstart=
6、""setr=newregexpr.ignorecase=truer.global=truer.pattern=""&start&".+?"&over&""setmatches=r.execute(lcase(str))setr=nothingstart=replace(start,"","")over=replace(over,"","")foreachmatchinmatchestmpurl=split(trim(replace(replace(lcase(match.valu
7、e),"","")),"href=")(1)ifinstr(tmpurl,"")>0thentmpurl=split(tmpurl,"")(0)endififinstr(tmpurl,chr(34))>0thentmpurl=replace(tmpurl,chr(34),"",1,1)tmpurl=split(tmpurl,chr(34))(0)endififinstr(tmpurl,chr(34)&"+")<1andinstr(tmpurl,"+"&chr(34))<1andinst
8、r(tmpurl,"'+")<1andinstr(tmpurl,"+'")<1andinstr(tmpurl,"javascript:")<1thentmpurl=replace(replace(tmpurl,chr(34),""),"'","")ifinstr(asp2html_gettag,"
9、"&tmpurl)<1andtmpurl<>"#"thenasp2html_gettag=asp2html_gettag&"
10、"&tmpurlendifendifnextifasp2html_gettag<>"
11、"thenasp2html_gettag=replace(asp2html_gettag,"
12、","",1,1)endifendfunctionfunctionasp2html_chgtag(str,path,surl)'替换链接为静态链接dimr,iurl,turliurl=replace(path,"?","?")iurl=replace(iurl,"+","+")iurl=replace(iurl,"$","$")