很多人在网说要全站转静态程序但是大多数都没结果的,所以小妹妹凭着一知半解的写了这个代码希望有了解 asp转静态技术 交流一下
QUOTE:<%
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
Function BytesToBstr(body,Cset)
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
%>
xmlhttp.asp
QUOTE:<!--#include file="xmlhttp.asp"-->
<%
url="co.asp?id=2,"
wb_cx=PcMane(url)
IF wb_cx<>"" THEN
RESPONSE.Write("开始转换静态过程")
fso_wstr=split(wb_cx,",")
for i=0 to UBound(fso_wstr)-1
qman_html_min=(thhs(thhs(fso_wstr(i),"?","~"),".asp","")&".html")
qman_html_min=getHTTPPage(http&fso_wstr(i))
for j=0 to UBound(fso_wstr)-1
qman_html_min=thhs(qman_html_min,fso_wstr(j),thhs(thhs(fso_wstr(j),"?","~"),".asp","")&".html")
qman_html_min=thhs(qman_html_min,".html&",".html?")
next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
FilePath = Server.MapPath(qman_html_url)
Set fout = fso.CreateTextFile(FilePath)
qman_html_min=qman_html_min&"<script type='text/javascript'>"&_
"if (!document.location.search == '')"&_
"{"&_
"var h=location.href;"&_
"var r=new RegExp('[^\\?]*/([^&]*)','i');"&_
"var t=h.match(r);"&_
"if (t)"&_
"{"&_
"var str = t[1]; "&_
"newstr=str.replace('.html?','&'); "&_
"location=newstr+'.html';"&_
"}"&_
"}"&_
"</script>"
fout.WriteLine qman_html_min
NEXT
else
response.Write("没有成功")
END IF
function PcMane(url)
dim arrID
arrID =FormateOrderBy(arrID&url)
http="http://www.gong-z.com/"
DG_Split=Split(arrID,",")
for i=0 to Ubound(DG_Split)-1
DG_href="<(a href=)[\w].+?>"
DG_wstr_1=DG_wstr_1&stripHTML(">",stripHTML("<a href=",RegExpTest(DG_href,getHTTPPage(http&DG_Split(i)))))
next
if len(arrID)=len(FormateOrderBy(DG_wstr_1)) then
PcMane=FormateOrderBy(DG_wstr_1)
exit function
else
arrID=PcMane(DG_wstr_1)
end if
PcMane = FormateOrderBy(arrID)
end function
Function FormateOrderBy(OrderByText)
Dim tmp,tmp2,i,j
tmp3=""
tmp = Split(OrderByText,",")
For i=0 To Ubound(tmp)-1
For j=i+1 To Ubound(tmp)
If UCase(Trim(tmp(i)))=UCase(Trim(tmp(j))) Then
tmp(j)=""
End If
Next
Next
tmp2=""
For i=0 To Ubound(tmp)
If tmp(i)<>""Then tmp2=tmp2&tmp(i)&","
Next
FormateOrderBy=Left(tmp2,Len(tmp2))
End Function
'正则函数
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match in Matches
RetStr = RetStr & Match.Value&","
Next
RegExpTest = RetStr
End Function
Function stripHTML(patrn,strHTML)
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern =patrn
strOutput = objRegExp.Replace(strHTML, "")
stripHTML = strOutput
Set objRegExp = Nothing
End Function
%>
利用Asp生成整站静态
80酷酷网 80kuku.com