ASP Thief Acquisition Program principle and common function method _ Thieves/Collection

Source: Internet
Author: User
The advantages of using the acquisition program are: no maintenance site, because the data acquisition program from other sites, it will be updated with the site, you can save server resources, general acquisition program on several files, all Web content is from other sites. Disadvantages are:

Unstable, if the target site error, the program will also be wrong, and, if the target site to upgrade maintenance, then the acquisition program to make corresponding changes; speed, because it is a remote call, speed and on the local server reading data than it is certainly slower.

One, case
The following is a brief description of the application of XMLHTTP in ASP
Copy Code code as follows:

<%
' Common functions
' 1, enter URL target page address, return value Gethttppage is the HTML code of the target page
function gethttppage (URL)
Dim Http
Set Http=server.createobject ("MSXML2. XMLHTTP ")
Http.open "Get", Url,false
Http.send ()
If Http.readystate<>4 Then
Exit function
End If
Gethttppage=bytestobstr (Http.responsebody, "GB2312")
Set http=nothing
If Err.number<>0 then err. Clear
End Function
' 2, the conversion of XMLHTTP, directly with the use of Chinese characters to call the Web page will be chaos, can be converted through the ADODB.stream component
Function Bytestobstr (body)
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 = "GB2312" converts the original default UTF-8 encoding to GB2312 encoding, otherwise directly using the XMLHTTP component to invoke the page with Chinese characters will be garbled
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function
' Try to invoke http://www.google HTML content below
Dim url,html
Url= "Http://www.google";
Html = Gethttppage (URL)
Response.Write Html
%>


Two, a few commonly used functions
InStr function
Describes the position that returns the first occurrence of a character (string2) string in another string (string1).
Grammar InStr (string1, string2)
For example:
Dim SearchString, SearchChar
SearchString = "Http://www.google" ' string to search in.
SearchChar = "blue1000" searches "blue1000".
MYBK = Instr (searchstring, SearchChar) ' Return 8
' Returns ' 0 if it is not found, for example:
SearchChar = "BK"
MYBK = Instr (searchstring, SearchChar) ' return 0
Mid function
Description: Returns a specified number of characters from a string.
Grammar Mid (String, start, over)
For example:
Dim MYBK
MYBK = Mid ("Our BK (www.google) Design", 7, 12) ' intercept string ' our BK (www.google) Design ' 7th character after 12 characters ' now MYBK value becomes ' Www.google '
Replace function
Dim SearchString, SearchChar
SearchString = "Our BK design is a website construction resource site" ' The string to search in.
SearchString =replace (searchstring, "BK Design", "Www.google") ' At this point the SearchString value becomes "Our Www.google is a website Construction resource website"

Iii. intercepting the HTML code for the specified area
For example, I just want to get the text section between "<td>" and "</td>" in the following HTML code:
&LT;TITLE&GT;BK (www.google) Google search engine </title>
<body>
<table>
<tr><td></td></tr>
&LT;TR&GT;&LT;TD id= "Content" &GT;BK (www.google) Google search engine is a lot of resources site ......</td></tr>
</table>
</body>
<%
......
Dim STRBK,START,OVER,RSBK
Strbk=gethttppage (Address of Web page)
Start=instr (STRBK, "<td id=" "Content" ">") ' The role here is to get the location where the string starts. Here to ask someone: The original code is &LT;TD id= "content", how you call here is &LT;TD id= "content" "> Ah? Answer: In ASP (in the case of VBScript, it is true that a double quotation mark is used in two double quotes. , because double quotes are sensitive characters for the program. Over=instr (STRBK, "...</td></tr>") ' role here is to get the location of the end of the string. "Here again asked:" (: The program calls the HTML code why more than 3 points in front of "..." Ah?) A: Hint: The above line also has a </td></tr&gt, if this place with </td></tr>, the program will mistakenly put the above line of </td></tr> As you want to get the end part of the string. Rsbk=mid (Strbk,start,over-start) ' role here is to remove the string between the start character and the over character in the STRBK. The mid function I also said in the previous section, Over-start is to calculate the distance between the start and end positions, that is, the number of characters.
Response.Write (RSBK) ' The final output of the program get content
%>
Do not be happy too early, when you run, you will find the page's HTML code error, why? Because you get the HTML code is: &LT;TD id= "Content" &GT;BK (www.google) Google search engine is a lot of resources site ...
Did you see that? There are incomplete HTML code AH! What do we do? Start=instr (STRBK, "<td id=" "Content" ">") this statement gets the "<td id=" Content ">" in


Number of positions in the STRBK, now that we can add 17 to the end of the program statement, the program will point to the character <td id= "Content" >.
OK, the program will change to this:
<%
......
Dim STRBK,START,OVER,RSBK
Strbk=gethttppage (Address of Web page)
Start=instr (STRBK, "<td id=" "Content" ">") + 17
Over=instr (STRBK, "...</td></tr>") ' Here you can also subtract seven (-7) to remove 3 points
Rsbk=mid (Strbk,start,over-start)
Response.Write (RSBK)
%>
This is OK, we will be able to steal what we want to display in our own page, hehe ~

Iv. Delete or modify the acquired characters
Replace "BK" in RSBK with "BK": Www.google
Rsbk=replace (RSBK, "BK (Www.google)", "BK")
Or simply delete the words "(www.google)":
Rsbk=replace (RSBK, "(Www.google)", "")
Okay, now RSBK has become: "BK Google search engine is a lot of resources site ...". But in fact, there may be situations where the Replace function is not appropriate, such as we want to remove all the connections from a string. A connection may include many types, Replace can only replace one of the specific one, we can not use one another corresponding replace function to substitute it?
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.