日期:2014-05-16  浏览次数:20838 次

怎么能让asp+ajax 实现边采集边显示采集结果呢?
我这自己写了个采集程序,是asp+ajax的。
采集界面就两个按钮,一个开始采集  一个停止采集
当点击的开始采集的时候  就通过ajax异步调用采集文件news_gathering_key.asp。
news_gathering_key.asp 这文件里面有显示采集标题、日期、源地址等等信息。
现在采集一切正常,可就是很不友好,我点击开始采集,页面什么都没动,值得采集完了,才全部显示出来。。。
我现在想的是怎么能实现 采集一条显示一条的采集结果呢?

news_gathering_key.asp:

call getpbody("http://tech.qq.com/l/it/itnews/itnews.htm")

function getpbody(url) 
dim objxml
on error resume next
set objxml = createobject("microsoft.xmlhttp") 
with objxml 
.open "get", url, false, "", "" 
.send 
getbody = .responsebody
end with 
getbody=bytestobstr(getbody,"gb2312")
if len(getbody)<>0 then
call splitre(getbody)
end if
'response.Write getbody
set objxml = nothing 
end function


function getcbody(url,k) 
dim objxmlx
on error resume next
set objxmlx = createobject("microsoft.xmlhttp") 
with objxmlx
.open "get", url, false, "", "" 
.send 
getbody = .responsebody
end with 
getbody=bytestobstr(getbody,"gb2312")
if len(getbody)<>0 then
call splitrc(getbody,k)
end if
'response.Write getbody
set objxmlx = nothing 
end function

'使用adodb.stream处理二进制数据
function bytestobstr(strbody,codebase)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write strbody
objstream.position = 0
objstream.type = 2
objstream.charset = codebase
bytestobstr = objstream.readtext 
objstream.close
set objstream = nothing
end function



function splitre(str)
Dim strurl(10000),strtxt(10000),strtim(10000),strContent(10000)
str=replace(str,"""","'")
str1=split(str,"<div class='mod newslist'>")
str2=split(str1(1),"</div>")
strx=replace(replace(replace(replace(str2(0),"<ul><li>",""),"<a target='_blank' href='",""),"</ul>",""),"</li>","")
strx=replace(replace(replace(replace(replace(replace(strx,"<li>",""),"<span class='pub_time'>",""),"</span>","|||"),"·",""),"'>","|"),"</a> ","|")
strx=replace(strx,"&#160;"," ")
strxx=split(strx,"|||")
for i=0 to ubound(strxx)
strtex=split(strxx(i),"|")
if ubound(strtex)>=2 then
response.Write "<font color=blue>开始采集新闻:"&strtex(1)&" &nbsp;&nbsp;新闻地址:"&strtex(0)&"</font><br><br>"
set ck=server.CreateObject("adodb.recordset")
ck.open "select * from News_gathering where url='"&strtex(0)&"'",conn,1,1
if not ck.eof then
cktemp=1
else
cktemp=0
end if
ck.close
set ck=nothing
strurl(i)=strtex(0)
strtxt(i)=strtex(1)
if cktemp=1 then
response.Write "<font color=red>新闻:"&strtxt(i)&" 已经存在,不予采集。</font><br><br>"
else
response.Write "<font color=green>新闻:"&strtex(1)&" 采集完毕</font><br><br>"
end if
strtim(i)=strtex(2)
end if
next
for i=0 to ubou