<%
'聲明取得目標信息的函數,通過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"采集完畢!"
%>