浅谈自动采集程序及入库
程序员文章站
2022-05-18 14:18:44
<%'声明取得目标信息的函数,通过xml组件进行实现。function geturl(url) set retrieval = createobject("micro...
<%
'声明取得目标信息的函数,通过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"采集完毕!"
%>
'声明取得目标信息的函数,通过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"采集完毕!"
%>
上一篇: leetcode226. 翻转二叉树
下一篇: LeetCode226.翻转二叉树