ASP 自動(dòng)采集實(shí)現(xiàn)代碼
更新時(shí)間:2009年11月30日 19:35:03 作者:
通過(guò)XML中的XMLHTTP組件調(diào)用其它網(wǎng)站上的網(wǎng)頁(yè),然后批量截取或替換原有的信息使其轉(zhuǎn)化成變量后再一一儲(chǔ)存到數(shù)據(jù)庫(kù)中。
其主要的優(yōu)點(diǎn)便是無(wú)需再手工添加大量的信息了,可以指定對(duì)某一個(gè)站信息的截取進(jìn)行批量錄入,達(dá)到省時(shí)省力的目的。與其單純的ASP小偷程序不同的是:它已經(jīng)不再依賴(lài)其目標(biāo)網(wǎng)站。
參考代碼:
<%
'聲明取得目標(biāo)信息的函數(shù),通過(guò)XML組件進(jìn)行實(shí)現(xiàn)。
Function Geturl(/blog/url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False
.Send
GetURL = bytes2bstr(.responsebody)
'對(duì)取得信息進(jìn)行驗(yàn)證,如果信息長(zhǎng)度小于100則說(shuō)明截取失敗
if len(.responsebody)<100 then
response.write "獲取遠(yuǎn)程文件 <a href="&url&" target=_blank>"&url&"</a> 失敗。"
response.end
end if
End With
Set Retrieval = Nothing
End Function
' 二進(jìn)制轉(zhuǎn)字符串,否則會(huì)出現(xiàn)亂碼的!
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開(kāi)始截取,到Last為結(jié)束
Function GetKey(HTML,Start,Last)
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
End Function
Dim Softid,Url,Html,Title
'獲取要取頁(yè)面的ID
SoftId=Request("Id")
Url="http://www3.skycn.com/soft/"&SoftId&".html"
Html = Geturl(/blog/Url)
'以截取天空軟件的軟件名為例子
Title = GetKey(Html,"<font color='#004FC6' size='3'>","</font></b></td></tr>")
'打開(kāi)數(shù)據(jù)庫(kù),準(zhǔn)備入庫(kù)
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"采集完畢!"
%>
參考代碼:
復(fù)制代碼 代碼如下:
<%
'聲明取得目標(biāo)信息的函數(shù),通過(guò)XML組件進(jìn)行實(shí)現(xiàn)。
Function Geturl(/blog/url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False
.Send
GetURL = bytes2bstr(.responsebody)
'對(duì)取得信息進(jìn)行驗(yàn)證,如果信息長(zhǎng)度小于100則說(shuō)明截取失敗
if len(.responsebody)<100 then
response.write "獲取遠(yuǎn)程文件 <a href="&url&" target=_blank>"&url&"</a> 失敗。"
response.end
end if
End With
Set Retrieval = Nothing
End Function
' 二進(jìn)制轉(zhuǎn)字符串,否則會(huì)出現(xiàn)亂碼的!
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開(kāi)始截取,到Last為結(jié)束
Function GetKey(HTML,Start,Last)
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
End Function
Dim Softid,Url,Html,Title
'獲取要取頁(yè)面的ID
SoftId=Request("Id")
Url="http://www3.skycn.com/soft/"&SoftId&".html"
Html = Geturl(/blog/Url)
'以截取天空軟件的軟件名為例子
Title = GetKey(Html,"<font color='#004FC6' size='3'>","</font></b></td></tr>")
'打開(kāi)數(shù)據(jù)庫(kù),準(zhǔn)備入庫(kù)
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"采集完畢!"
%>
相關(guān)文章
用XML+FSO+JS實(shí)現(xiàn)服務(wù)器端文件的選擇效果
用XML+FSO+JS實(shí)現(xiàn)服務(wù)器端文件的選擇效果實(shí)現(xiàn)代碼,需要的朋友可以參考下2006-06-06光碟工具 Alcohol 120% v1.9.6.4719 下載(附序列號(hào)注冊(cè)碼)
光碟工具 Alcohol 120% v1.9.6.4719 下載(附序列號(hào)注冊(cè)碼)...2007-02-02發(fā)一個(gè)采集(小偷)用的類(lèi),ASP+緩存實(shí)現(xiàn)
發(fā)一個(gè)采集(小偷)用的類(lèi),ASP+緩存實(shí)現(xiàn)...2007-02-02ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門(mén)教程
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門(mén)教程...2006-06-06網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略
網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略...2006-08-08