我们拿个简单点的东西来研究一下吧,qq网站上的天气预报程序
代码如下:
1 <%2 OnErrorResumeNext
3 Server.Scripttimeout=9999999
4 FunctionGethttppage(Path)
5 T=Getbody(Path)
6 Gethttppage=Bytestobstr(T,"Gb2312")
7 EndFunction
8
9 '首先,进行小偷程序的一些初始化设置,以上代码的作用分别是忽略掉所有非致命性错误,把小偷程序的运行超时时间设置得很长(这样不会出现运行超时的错误),转换原来默认的utf-8编码转换成gb2312编码,否则直接用xmlhttp组件调用有中文字符的网页得到的将是乱码。
10
11 FunctionGetbody(Url)
12 OnErrorResumeNext
13 SetRetrieval=Createobject("Microsoft.Xmlhttp")
14 WithRetrieval
15 .Open"Get",Url,False,"",""
16 .Send
17 Getbody=.Responsebody
18 EndWith
19 SetRetrieval=Nothing
20 EndFunction
21
22 '然后调用xmlhttp组件创建一个对象并进行初始化设置。
23
24 FunctionBytestobstr(Body,Cset)
25 DimObjstream
26 SetObjstream=Server.Createobject("Adodb.Stream")
27 Objstream.Type=1
28 Objstream.Mode=3
29 Objstream.Open
30 Objstream.WriteBody
31 Objstream.Position=0
32 Objstream.Type=2
33 Objstream.Charset=Cset
34 Bytestobstr=Objstream.Readtext
35 Objstream.Close
36 SetObjstream=Nothing
37 EndFunction
38
39 FunctionNewstring(Wstr,Strng)
40 Newstring=Instr(Lcase(Wstr),Lcase(Strng))
41 IfNewstring<=0ThenNewstring=Len(Wstr)
42 EndFunction
43
44 '处理抓取回来的数据需要调用adodb.Stream组件并进行初始化设置。%>