ASP thieves (remote Data Acquisition) Program Introduction Tutorial _ Thieves/Collection

Source: Internet
Author: User
"Thieves" here refers to the use of XML in the ASP XMLHTTP components to provide a powerful function, the remote Web site data (Pictures, Web pages and other files) crawled to the local, after a variety of processing to display on the page or stored into the database of a class of programs. You can use this kind of thief program to accomplish some seemingly impossible tasks in the past, such as cynical a page of a station to become your own page, or save some data (articles, pictures) of a station to the local database. The advantages of "thieves" are: no need to maintain the site, because the Thief program data from other sites, it will be updated with the site update, you can save a lot of server resources, the General Thief program on several files, all Web content is from other sites. The disadvantage is: instability, if the target site error, the program will also be wrong, and, if the target site to upgrade maintenance, then the Thief 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. What, it sounds amazing, doesn't it? Let's start by learning some of the basics of "thief" programs.

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

The code is as follows:

1<%
2OnErrorResumeNext
3Server.ScriptTimeout=9999999
4FunctionGethttppage (Path)
5T=GetBody (Path)
6Gethttppage=Bytestobstr (T,"Gb2312")
7End Function
8
9'First of all, to carry out some initialization of the thief program, the function of the above code is to ignore all non-fatal errors, the Thief program's running timeout is set very long (this will not run out of error), the original default utf-8 encoding converted to gb2312 encoding, Otherwise, directly using the XMLHTTP component to invoke a page with Chinese characters will be garbled.
10
11FunctionGetBody (URL)
12OnErrorResumeNext
13SetRetrieval=CreateObject("Microsoft.XMLHTTP")
14WithRetrieval
15. Open"Get"UrlFalse,"",""
16. Send
17GetBody=. Responsebody
18EndWith
19SetRetrieval=Nothing
20End Function
21st
22'The XMLHTTP component is then called to create an object and initialize the settings.
23
24FunctionBytestobstr (Body,cset)
25DimObjstream
26SetObjstream=Server.CreateObject("ADODB.stream")
27objStream.Type=1
28Objstream.mode=3
29objStream.Open
30Objstream.write body
31Objstream.position=0
32objStream.Type=2
33Objstream.charset=Cset
34Bytestobstr=Objstream.readtext
objstream.close
+ Set  objstream  =   Nothing
notoginseng end function

\ Function  newstring (wstr,strng)
newstring = Instr ( Lcase (WSTR), Lcase (strng)
0 If  newstring <=   Then  newstring = Len (wstr)
, end function
The
all ' handles crawl back data needs to call ADODB. Stream component and initialize the settings. %>
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.