資源描述:
《關(guān)于asp程序生成靜態(tài)頁(asp轉(zhuǎn)html)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、關(guān)于asp程序生成靜態(tài)頁(asp轉(zhuǎn)html)--------------------------------------------------------------------------------網(wǎng)上這類的文章很多,大多數(shù)都是轉(zhuǎn)載的,無非是兩種:第一種:利用模板生成html文件;第二種:利用xmlhttp訪問目標(biāo)程序并保存成html第一種的麻煩之處在于要制作模板,做大型項(xiàng)目還好,小項(xiàng)目的話,靈活性就不足了;第二種有一個(gè)很大的缺陷:生成的靜態(tài)頁里的鏈接還是指向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,"http://","/")asp2html_cpath=strendfunctionfunctionasp2html_b2s(str)'轉(zhuǎn)換二進(jìn)制數(shù)據(jù)為文本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)'替換鏈接為靜態(tài)鏈接dimr,iurl,turliurl=replace(path,"?","?")iurl=replace(iurl,"+","+")iurl=replace(iurl,"$","$")