Thief procedure principle and simple example

xiaoxiao2021-03-06  53

(1) principle

The thief program actually invokes the webpage on other websites through the XMLHTTP components in XML. For example, the news thief program, many of them call the Sina's news page, and some replacements are made, and the advertisements have also been filtered. The advantages of the thief program are: No need to maintain the website, because the data in the thief program is from other websites, which will be updated with the update of the site; save server resources, general thief procedures, all web content is From other websites. Disadvantages: Unstable, if the target website is wrong, the program will make an error, and if the target website is upgraded, then the thieves should be modified accordingly; speed, because it is remote call, speed, and read data on the local server Compared to, it must be slower.

(2) case

The following is XMLHTTP

Application in ASP is a brief description

<%

'Common function

'1, enter the URL target web address, return value gethttppage is the HTML code for 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, conversion of Chambar, directly using the web page with Chinese characters with Chinese characters will be Hemma, can be converted via AdoDb.Stream components

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

'under

Interview call http://www.373.cn/ of HTML content

DIM URL, HTML

URL = "http://www.373.cn/"

HTML = gethttppage (URL)

Response.write HTML

%>

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

New Post(0)