1<%
2‘’声明取得目标信息的函数,通过XML组件进行实现。
3Function GetURL(url)
4Set Retrieval = CreateObject("Microsoft.XMLHTTP")
5With Retrieval
6.Open "GET", url, False
7.Send
8GetURL = bytes2bstr(.responsebody)
9‘’对取得信息进行验证,如果信息长度小于100则说明截取失败
10if len(.responsebody)<100 then
11response.write "获取远程文件 <a href="&url&" target=_blank>"&url&"</a> 失败。"
12response.end
13end if
14
15End With
16Set Retrieval = Nothing
17End Function
18‘’ 二进制转字符串,否则会出现乱码的!
19function bytes2bstr(vin)
20strreturn = ""
21for i = 1 to lenb(vin)
22thischarcode = ascb(midb(vin,i,1))
23if thischarcode < &h80 then
24strreturn = strreturn & chr(thischarcode)
25else
26nextcharcode = ascb(midb(vin,i+1,1))
27strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
28i = i + 1
29end if
30next
31bytes2bstr = strreturn
32end function
33‘’声明截取的格式,从Start开始截取,到Last为结束
34Function GetKey(HTML,Start,Last)
35filearray=split(HTML,Start)
36filearray2=split(filearray(1),Last)
37GetKey=filearray2(0)
38End Function
39
40Dim Softid,Url,Html,Title
41
42‘’获取要取页面的ID
43
44SoftId=Request("Id")
45
46 Url="http://www3.skycn.com/soft/"&SoftId&".html"
47
48 Html = GetURL(Url)
49
50‘’以截取天空软件的软件名为例子
51
52 Title = GetKey(Html,"<font color=‘’#004FC6‘’ size=‘’3‘’>","</font></b></
td></tr>")
53
54‘’打开数据库,准备入库
55
56dim connstr,conn,rs,sql
57
58connstr="DBQ="+server.mappath("db1.mdb")+";DefaultDir=;DRIVER={Microsoft A
clearcase/" target="_blank" >ccess Driver (*.mdb)};"
59
60set conn=server.createobject("ADODB.CONNECTION")
61
62conn.open connstr
63
64set rs=server.createobject("adodb.recordset")
65
66sql="select [列名] from [表名] where [列名]=‘’"&Title&"‘’"
67
68rs.open sql,conn,3,3
69
70if rs.eof and rs.bof then
71
72rs("列名")=Title
73
74rs.update
75
76set rs=nothing
77
78end if
79
80set rs=nothing
81
82Response.Write"采集完毕!"
83
84%>
原文转自:http://www.ltesting.net