The introduction tutorial of the ASP thief (remote data acquisition) program is selected from Arcow's Blog

xiaoxiao2021-03-06  42

The "thief" mentioned here refers to the powerful feature provided by the XMLHTTP components in the ASP, putting data on the remote website (picture,

Web and other files) Claps the local, displayed on the page or store into the database after various processes

program. You can pass this thief

The program has completed the task that seems to be completely impossible. For example, the pages of a station have turned into their own pages, or save some of the data (articles, pictures, pictures) of a station to the local database. The advantages of "thief" are: no need to maintain the website, because the thief

The data in the program is from other websites, which will be updated with the update of the site; saving a large number of server resources, general thieves

The program is a few files, all

Web page content is from other websites. The disadvantage is: unstable, if the target website is wrong,

The program will also be wrong, and if the target website is upgraded, then the thief

The program should also be modified; speed, because it is a remote call, speed, and more than one read data on the local server, it must be slower. How, it sounds amazing? We will start to learn some "thieves"

Getting started knowledge of the program!

Let's take a simple point to study, the weather forecast on the QQ website

program

code show as below:

<%

ON Error ResMe next

Server.scripttimeout = 9999999

Function gethttppage (PATH)

T = getBody (PATH)

gethttppage = Bytestobstr (t, "GB2312")

END FUNCTION

'First, carry a thief

Some of the initialization settings of the program, the role of the above code is ignored all non-poor mistakes, respectively, and thieves the thief

The run timeout time of the program is set long (this does not have an error that runs timeout), the converted the default UTF-8 encoding is converted into GB2312 encoding, otherwise it is called directly with the XMLHTTP component.

The web page will be garbled.

Function GetBody (URL)

ON Error ResMe next

Set Retrieval = CreateObject ("Microsoft.xmlhttp")

With retrieval

.Open "get", URL, FALSE, "" "" "

Ssend

GetBody = .Responsebody

End with

Set Retrieval = Nothing

END FUNCTION

'Call the XMLHTTP component to create an object and perform initialization settings.

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

'Handling the data that can be caught needs to call the AdoDB.Stream component and perform initialization settings. %>

'The following is the page display section

<%

DIM WSTR, STR, URL, START, OVER, CITY

'Define some variables that need to be used

City = request.queryString ("id")

'

The ID variable (ie, the user selected by the user) is assigned to the ID

URL = "http://appnews.qq.com/cgi-bin/news_qq_search?city=" & city & ""

'The page address that needs to be grasped here, of course, you can also specify an address without using variables.

WSTR = gethttppage (URL)

'Get all the data for the specified page

Start = newstring (wstr, "")

'Set the heads of the data that need to be processed, this variable is set to different situations, and the specific content can be determined by viewing the source code of the page you want to capture. Because in this

In the program, we need to catch the entire page, so set all the capture of the page. Note that the content set must be unique, and cannot be repeated.

Over = newstring (wstr, "")

'And START are the tail of the data that needs to be processed, the same, the content set must be unique in the page.

Body = MID (WSTR, START, OVER-START)

'Set the range of the display page

'When you use Qiankun Move , you can replace the characters specified in the data by replacing.

Body = Replace (Body, "Skin1", "Weather Forecast - Sk Network")

Body = replace (body, "http://appnews.qq.com/cgi-bin/news_qq_search?city", "tianqi.

ASP? ID ")

'this

Alternative work has been completed in the program, and similar replacement operations can be proceed if there are other needs.

Response.Write Body

%>

After replacing the content you need to modify, you can display the modified content on the page. Hereed

Program end

Program use method and results: After the above code is removed, it is saved as Tianqi.

ASP, uploaded to space that supports ASP and XML, run in the browser. You can be in this

On the basis of the program, further interface beauty is performed or

Program optimization.

The above is just some primary applications for XMLHTTP components. It is actually a lot of features that it can implement, such as saving remote pictures to local servers, with AdoDb.stream components, can save the acquired data into the database. The role and use range of thieves are wide. But you can't take a violation of law!

Maybe someone is asking, this "thief"

Is the program just ASP patents? Non-also, PHP can achieve the same effect like the FOPEN function, because PHP itself has various characteristics, the thief written

Compared with ASP, there are obvious advantages in volume and execution efficiency, but is limited to space, which is not explained here.

转载请注明原文地址:https://www.9cbs.com/read-52950.html

New Post(0)