<%
'====================================== ===
class EngineerSearch
'Laolong:laolong9999@sina.com
': Simulate XML to obtain http tag resources (you will know why XML is useful after using it:))
'Use engine search (Display engine information or information on its hyperlinked website or directly related information of a specified page, using regular expressions and xmlHttp,
'The use of the program needs to construct regular expressions)
'-------- -------------------------------------------------- -----
private oReg,oxmlHttp'a regular, a Microsoft xmlhttp
'-------------------------- ------------------------------------
public sub class_initialize()' object creation trigger
set oReg=new regExp
oReg.Global=true
oReg.IgnoreCase=true
set oXmlHttp=server.createobject("Microsoft.XmlHttp")
end sub
'--- -------------------------------------------------- ----------
public sub class_terminate()'Object destruction trigger
set oReg=nothing'You must manually release the self-built objects in the class, asp only automatically releases the objects defined by the class
set oXmlHttp=nothing
If typename(tempReg)<>"nothing" then'The object in the method body releases resources
set tempReg=nothing
end if
end sub
' -------------------------------------------------- -------------
'Engine level search
public function engineer(url,EngineerReg)
'Function introduction: Get the return information of url (usually used for engine search) , extract the specific information of EngineerReg, and return the matches set to
' function name. Obtain the URL query results, search for the results defined by engineerReg, and generate a matches collection.
'Since it is impossible to create a collection and operate the number of collections (vbscript), it is best to traverse the collection yourself, or you can consider a two-dimensional array
dim strConent
strContent=oXmlHttp.open("get",url,false)
on error resume next
oXmlHttp.send()
if err.number<>0 then
exit function
end if
strContent=bytes2BSTR(oXmlHttp.responseBody)
if isnull(EngineerReg) then
engineer=AbsoluteURL(strContent,url)
else
oReg.Pattern= EngineerReg
set engineer=oReg.Execute(AbsoluteURL(strContent,url))
end if
end function
'---------------- ---------------------------------------------
'Chinese characters Coding, (Netizen)
public Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i 1,1))
strReturn = strReturn & Chr ( CLng(ThisCharCode) * &H100 CInt(NextCharCode))
i = i 1
End If
Next
bytes2BSTR = strReturn
End Function
'-------- -------------------------------------------------- -----
public Function SearchReplace(strContent,ReplaceReg,ResultReg)
'Replace, replace the string described by replaceReg in strContent with the string described by resultReg, and return to searchReplace
'Replace the regular replace is encapsulated.
oReg.Pattern=ReplaceReg
SearchReplace=oReg.replace(strContent,ResultReg)
End Function
'-------------------------- ---------------------------------------------
public Function AbsoluteURL( strContent, byval url)
'Change the relative URL in strContent to the absolute address of the url specified in oXmlHttp (http/https/ftp/mailto:)
'The regular rules can be modified.
dim tempReg
set tempReg=new RegExp
tempReg.IgnoreCase=true
tempReg.Global=true
tempReg.Pattern="(^.*/).*$"'Includes files The standard path of the name http://www.wrclub.net/default.aspx
Url=tempReg.replace(url,"$1")
tempReg.Pattern="((?:src|href).* ?=['u0022](?!ftp|http|https|mailto))"
AbsoluteURL=tempReg.replace(strContent,"$1" Url)
set tempReg=nothing
end Function
'------------------------------------------------ ---------------
end class
'============================ =============
%>
<%'Example
Response.CharSet = "GB2312"
dim mySearch
set mySearch=new EngineerSearch
'URL must be the complete address including the file extension. The result is a collection. Each item in the collection is an array. The subquery should be referenced like this: myMatches(0).subMatches(0)
set myMatches=mySearch .engineer("http://www.wrclub.net/default.aspx","
")
if myMatches.count=0 Then
response.write "Without you regular string"
end if
if myMatches.count>0 then
response.write myMatches.count&"
"
for each key in myMatches
response.write key. firstindex&":"&cstr(key.value)&"
"
next
end if
%>
More applications , as long as you can regularize