<script language=vbscript runat="server">
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
function ajaxread(theurl)
dim xmlhttp
set xmlhttp = createobject("microsoft.xmlhttp")
xmlhttp.open "get", theurl, false
xmlhttp.setrequestheader "content-type","text/html"
xmlhttp.send
dim htmlstr
htmlstr = bytes2bstr(xmlhttp.responsebody)
ajaxread = htmlstr
end function
</script>
<%
var adoconn;
function opendatabase(){
try{
adoconn = new activexobject("adodb.connection");
adoconn.open ("provider=microsoft.jet.oledb.4.0;data source="+server.mappath("getcaiku.mdb"));
}catch(e){
adoconn.close;
response.write("数据库连接出错,请检查连接字串。");
response.end;
}
}
function closedatabase(){
adoconn.close;
}
response.buffer = 1;
server.scripttimeout = 99999;
//////////可修改以下参数////////////////
var beginid = 230;//开始id
var endid = 500;//结束id
////////////////////////////////////////
var arr,tstr,tid,getdata;
var countid = 0;
response.write ("开始采集:从"+beginid+"到"+endid+"<hr>");
response.flush;
opendatabase();
var re=new regexp("<title>(.*?) - 彩酷</title>","ig");
for(var fi=beginid;fi<(endid+1);fi++){
tid = string(fi);
getdata = ajaxread("http://mms.caiku.com/sendcring.aspx?uid=0&id="+tid);
if(arr = re.exec(getdata)!=null){
tstr = string(regexp.$1);
if(tstr!=null&&tstr!="undefined"&&tstr!="")
tstr = tstr.replace("'","");
adoconn.execute("insert into getdata(title,tid)values('"+tstr+"',"+tid+")");
response.write (tid+":"+tstr+" ___>ok!<br>");
countid++;
response.flush
}
}
re.close;
closedatabase();
response.write ("<hr>采集完毕!共录入数据"+countid+"条。");
%>