日期:2010-09-10  浏览次数:20945 次

<%
'声明取得目标信息的函数,通过XML组件进行实现。
Function GetURL(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False
.Send
GetURL = bytes2bstr(.responsebody)
'对取得信息进行验证,如果信息长度小于100则说明截取失败
if len(.responsebody)<100 then
response.write "获取远程文件 <a href="&url&" target=_blank>"&url&"</a> 失败。"
response.end
end if
End With
Set Retrieval = Nothing
End Function

' 二进制转字符串,否则会出现乱码的!
function bytes2bstr(vin)
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function

'声明截取的格式,从Start开始截取,到Last为结束
Function GetKey(HTML,Start,Last)
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
End Function

Dim Softid,Url,Html,Title
'获取要取页面的ID
SoftId=Request("Id")
Url="http://www3.skycn.com/soft/"&SoftId&".html"
Html = GetURL(Url)
'以截取天空软件的软件名为例子
Title = GetKey(Html,"<font color='#004FC6' size='3'>","</font></b></td></tr>")

'打开数据库,准备入库
dim connstr,conn,rs,sql
connstr="DBQ="+server.mappath("db1.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset")
sql="select [列名] from [表名] where [列名]='"&Title&"'"
rs.open sql,conn,3,3
if rs.eof and rs.bof then
rs("列名")=Title
rs.update
set rs=nothing
end if
set rs=nothing
Response.Write"采集完毕!"
%>