采集程序

采集程序,其实如果你懂一些ASP,了解自动采集程序的原理后,你会感觉实现自动化也是那么的简单.原理及优点:通过XML中的XMLHTTP组件调用其它网站上的网页,然后批量截取或替换原有的信息使其转化成变量后再一一储存到数据库中。

其主要的优点便是无需再手工添加大量的信息了,可以指定对某一个站信息的截取进行批量录入,达到省时省力的目的。与其单纯的ASP小偷程序不同的是:它已经不再依赖其目标网站。
简单事例:

 程序代码
<%
'声明取得目标信息的函数,通过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"采集完毕!"
%>
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章