1<%
2On Error Resume Next
3Server.Scripttimeout=9999999
4Function Gethttppage(Path)
5T = Getbody(Path)
6Gethttppage=Bytestobstr(T,"Gb2312")
7End Function
8
9‘’ 首先,进行小偷程序的一些初始化设置,以上代码的作用分别是忽略掉所有非致命性错误,把小偷程序的运行超时时间设置得很长(这样不会出现运行超时的错误),转换原来默认的utf-8编码转换成gb2312编码,否则直接用xmlhttp组件调用有中文字符的网页得到的将是乱码。
10
11Function Getbody(Url)
12On Error Resume Next
13Set Retrieval = Createobject("Microsoft.Xmlhttp")
14With Retrieval
15.Open "Get", Url, False, "", ""
16.Send
17Getbody = .Responsebody
18End With
19Set Retrieval = Nothing
20End Function
21
22‘’然后调用xmlhttp组件创建一个对象并进行初始化设置。
23
24Function Bytestobstr(Body,Cset)
25Dim Objstream
26Set Objstream = 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
35Objstream.Close
36Set Objstream = Nothing
37End Function
38
39Function Newstring(Wstr,Strng)
40Newstring=Instr(Lcase(Wstr),Lcase(Strng))
41If Newstring<=0 Then Newstring=Len(Wstr)
42End Function
43
44‘’处理抓取回来的数据需要调用adodb.Stream组件并进行初始化设置。%>
原文转自:http://www.ltesting.net