Use regular xmlHttp to steal) _ javascript skills

Source: Internet
Author: User
Use regular xmlHttp to steal (convert) The Code is as follows:


<%
'================================================ =
Class EngineerSearch
'Long: laolong9999@sina.com
': Simulates XML to obtain http tag resources (you can see why XML is useful after you have used it :))
'Use the engine to search (display the engine information, the information on its hyper-connected website, or the information directly related to a specified page, using regular expressions and xmlHttp,
'The program needs to construct a regular expression)
'---------------------------------------------------------------
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 '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 "method, objects in the body release resources.
Set tempReg = nothing
End if
End sub
'---------------------------------------------------------------
'Engine-level Search
Public function engineer (url, EngineerReg)
'Function Introduction: Obtain the returned url Information (usually used for engine search), extract the specific information of EngineerReg, and return the matches set
'Function name. Obtain the url query results, search for the results defined using the engineerReg regular expression, and generate a matches set,
'Because you cannot create a set or operate on the number of sets (vbscript), You 'd better traverse the set yourself. You can also consider two-dimensional arrays.
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 character encoding, (net man)
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, resulregulatory)
'Replace the string described by replaceReg in strContent with the one described by resulreg, and return it to searchReplace.
'Encapsulates the regular expression replace.
OReg. Pattern = ReplaceReg
SearchReplace = oReg. replace (strContent, resulregulatory)
End Function
'---------------------------------------------------------------
Public Function AbsoluteURL (strContent, byval url)
'Convert the relative URL in strContent to the absolute address of the url specified in oXmlHttp (http/https/ftp/mailto :)
'Regular expressions can be modified.
Dim tempReg
Set tempReg = new RegExp
TempReg. IgnoreCase = true
TempReg. Global = true
TempReg. Pattern = "(^. * \/). * $" 'standard path http://www.wrclub.net/default.aspx with file names
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 that contains the file extension. The result is a set. Each item in the set is an array. We should reference the subquery: myMatches (0). subMatches (0)
Set myMatches = mySearch. engineer ("http://www.wrclub.net/default.aspx ","")
If myMatches. count = 0 Then
Response. write "without your 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
%>


For more applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.