注册 登录
编程论坛 ASP技术论坛

采集程序的问题

theend12 发布于 2010-11-12 11:22, 502 次点击
<%
'声明取得目标信息的函数,通过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)    '这里是38行
GetKey=filearray2(0)
End Function

Dim Softid,Url,Html,Title

'获取要取页面的ID

SoftId=Request("Id")
Url="http://news.
Html = GetURL(Url)

'以截取天空软件的软件名为例子
Title = GetKey(Html,"<h3>","</h3>")

'打开数据库,准备入库
dim connstr,conn,rs,sql
connstr="DBQ="+server.mappath("db.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 [news] where [title]='"&Title&"'"
rs.open sql,conn,3,3
if rs.eof and rs.bof then
rs("title")=Title
rs.update
set rs=nothing
end if
set rs=nothing
Response.Write"采集完毕!"
%>


错误类型:
Microsoft VBScript 运行时错误 (0x800A0009)
下标越界: '[number: 1]'
/caiji.asp, 第 38 行
2 回复
#2
aspic2010-11-12 11:56
打印filearray出来看看就知道了 可能是length为0
#3
theend122010-11-12 12:16
可以了
Url="http://news.html"
结尾写错了。
也缺少了:rs.addnew
1