複製代碼代碼如下:
<%
'========================================
classEngineerSearch
':模擬XML獲取http標記資源(用過之後就知道為什麼XML有用:))
'利用引擎搜索(顯示引擎信息或其超連接網站上的信息或直接一個指定頁面的相關信息,利用正則和xmlHttp,
'程序的使用需要會構造正則)
'---------------------------------------------------------------
privateoReg,oxmlHttp'一個正則,一個微軟xmlhttp
'---------------------------------------------------------------
publicsubclass_initialize()'對象建立觸發
setoReg=newregExp
oReg.Global=true
oReg.IgnoreCase=true
setoXmlHttp=server.createobject("Microsoft.XmlHttp")
endsub
'---------------------------------------------------------------
publicsubclass_terminate()'對象銷毀觸發
setoReg=nothing'必須手動釋放class內的自建對象,asp只自動釋放由class定義的對象
setoXmlHttp=nothing
Iftypename(tempReg)<>"nothing"then'方法體內的對象釋放資源
settempReg=nothing
endif
endsub
'---------------------------------------------------------------
'引擎級搜索
publicfunctionengineer(url,EngineerReg)
'功能介紹:獲得url的返回信息(通常用於引擎查找),提取其中的EngineerReg的特定信息,返回matches集合到
'函數名。獲得url查詢結果,搜尋出用engineerReg正則定義的結果,生成一個matches集合,
'由於無法建立集合及操作集合個數(vbscript),最好再自己遍歷集合,也可以考慮二維數組
dimstrConent
strContent=oXmlHttp.open("get",url,false)
onerrorresumenext
oXmlHttp.send()
iferr.number<>0then
exitfunction
endif
strContent=bytes2BSTR(oXmlHttp.responseBody)
ifisnull(EngineerReg)then
engineer=AbsoluteURL(strContent,url)
else
oReg.Pattern=EngineerReg
setengineer=oReg.Execute(AbsoluteURL(strContent,url))
endif
endfunction
'---------------------------------------------------------------
'漢字編碼,(網人)
publicFunctionbytes2BSTR(vIn)
strReturn=""
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))