In fact, it is easy to do a thief .....................
To be a good thief is a bit difficult: P
This is a manuscript that I put to the computer newspaper. It is very simple, it is very rushing, there are many indifferent places, the masters are in trouble when they laugh, the original is to take a Alexa, I was revised when I was published. QQ weather forecast thief.
Flexible use XMLHTTP components
You can also do "thief"
Seeing this title, you can don't misunderstand. The "thief" mentioned here refers to the powerful features provided by XMLHTTP components in XML in ASP, grabbing data (pictures, web pages and other files) on the remote website. Taken to the local, displayed on the page or store a class of programs in the database after various processes. You can pass this thief program, complete the task that seems to be completely impossible, so that after stealing a station, turn into your own page, or save some data (articles, pictures) to some stations to Used in the local database. The advantages of "thief" are: no need to maintain the website, because the data in the thief program is from other websites, which will update with the website update; save a large number of server resources, the general thief process, several files, all web content They are all from other websites. The disadvantage is: unstable, if the target site is wrong, the program will also make mistakes, and if the target website is upgraded, then the thief program should be modified accordingly; speed, because it is remote call, speed, and read data on the local server Compared to, it must be slower. How, it sounds amazing? Let's start to learn some "thief" procedures!
Let's take a simple point to study, the weather forecasting procedure on the QQ website
Program Demo Address: http://www.gtocn.com/tianqi.asp
Source code download: http://www.gtocn.com/tianqi.txt
code show as below:
<%
ON Error ResMe next
Server.scripttimeout = 9999999
Function gethttppage (PATH)
T = getBody (PATH)
gethttppage = Bytestobstr (t, "GB2312")
END FUNCTION
'First, some initialization settings of the thief program, the role of the above code is ignored all non-poorly wrong errors, respectively, set the running timeout time of the thief program, which does not have an error that runs timeout), converted the original default UTF-8 encoding is converted into GB2312 encoding, otherwise it will be garbled with the web page with the XMLHTTP component.
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 = 3objstream.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 (i.e., the city 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 we need to catch the entire page in this program, set it to the page all grip? NBSP; W⒁ 猓 玫 玫 谌 谌 匦 匦 匦 婺 谌 ㄒ ㄒ 模 模 模 模 模 模 模 馗 馗 馗 馗 馗 ㄒ ㄒ 馗 谌 谌 谌 谌
Over = newstring (wstr, " html>")
'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
'The following is the time when you use the Qiankun Moves Dafa. 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")
The replacement work has been completed in this program. If you have any other needs, you can continue similar alternative operations.
Response.Write Body
%>
After replacing the content you need to modify, you can display the modified content on the page. To the end of this program
Procedure Usage and Result: After removing the above code, saved to tianqi.asp after removing the above code, and uploaded to the space that supports ASP and XML, running in the browser. You can further interface beauty or program optimization on this program.
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 there may be someone to ask, is this "thief" program just ASP's patents? Non-also, PHP can achieve the same effect like the FOPEN function. Due to the various characteristics of PHP itself, the written thieves and ASPs have obvious advantages in volume and implementation efficiency, but limited to space, here It will not be explained.