ASP thieves (Remote Data Acquisition)

Source: Internet
Author: User

Here, the "thief" refers to the use of the powerful functions provided by the XMLHTTP component in XML in ASP to capture data (images, webpages, and other files) on a remote website to a local device, after various processing, it is displayed on the page or stored in the database. Program . You can use this thief program to complete tasks that seem completely impossible in the past. For example, you can steal a website page and change it to your own page, or you can use some data of a website ( Article Images) are saved to the local database for use. "Thieves" have the following advantages: they do not need to maintain the website, because the data in the thief program comes from other websites and will be updated with the updates of the website; they can save a lot of server resources, generally, a thief program has several files, and all the webpage content comes from other websites. Disadvantages: unstable. If an error occurs on the target website, the program will also go wrong. If the target website is upgraded and maintained, the thief program must be modified accordingly; speed, because it is a remote call, it must be slower than reading data on the local server. How about it? It sounds amazing? Now let's start to learn more about the "thief" program!

Let's take a simple look at the weather forecast program on the QQ website.

CodeAs follows:

1 < %
2 On Error Resume Next
3 Server. scripttimeout = 9999999
4 Function Gethttppage (PATH)
5 T = Getbody (PATH)
6 Gethttppage = Bytestobstr (t, " Gb2312 " )
7 End Function
8
9 ' First, perform initialization settings for the thief program. The above code is used to ignore all non-fatal errors, set the running timeout time of the thief program to a long time (no running timeout error will occur) and convert the original default UTF-8 encoding to gb2312 encoding, otherwise, it is garbled to call a webpage with Chinese characters directly using the XMLHTTP component.
10
11 Function Getbody (URL)
12 On Error Resume Next
13 Set Retrieval = Createobject ( " Microsoft. XMLHTTP " )
14 With Retrieval
15 . Open " Get " , URL, False , "" , ""
16 . Send
17 Getbody = . Responsebody
18 End With
19 Set Retrieval = Nothing
20 End Function
21
22 ' Call the XMLHTTP component to create an object and perform initialization settings.
23
24 Function Bytestobstr (body, cset)
25 Dim Objstream
26 Set Objstream = Server. Createobject ( " ADODB. Stream " )
27 Objstream. Type = 1
28 Objstream. Mode = 3
29 Objstream. Open
30 Objstream. Write body
31 Objstream. Position = 0
32 Objstream. Type = 2
33 Objstream. charset = Cset
34 Bytestobstr = Objstream. readtext
35 Objstream. Close
36 Set Objstream = Nothing
37 End Function
38
39 Function Newstring (wstr, strng)
40 Newstring = Instr ( Lcase (Wstr ), Lcase (Strng ))
41 If Newstring <= 0 Then Newstring = Len (Wstr)
42 End Function
43
44 ' To process the captured data, call the ADODB. Stream component and perform initialization settings. %>

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.