一段采集程序代码

2018-09-06 11:24

阅读:535

  <%@LANGUAGE=JScriptCODEPAGE=936%>
<scriptlanguage=VBScriptrunat=Server>
Functionbytes2BSTR(vIn)
strReturn=
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR=strReturn
EndFunction

FunctionajaxRead(theURL)
dimXmlHttp
setXmlHttp=CreateObject(Microsoft.XMLHTTP)
XmlHttp.OpenGET,theURL,false
XmlHttp.setRequestHeaderContent-Type,text/HTML
XmlHttp.Send

dimhtmlstr
htmlstr=bytes2BSTR(XmlHttp.responseBody)
ajaxRead=htmlstr
EndFunction
</script>

<%
varADOConn;
functionOpenDatabase(){
try{
ADOConn.Open(Provider=Microsoft.Jet.Oledb.4.0;DataSource=+Server.MapPath(getcaiku.mdb));
}catch(e){
ADOConn.close;
Response.Write(数据库连接出错,请检查连接字串。);
Response.End;
}
}

functionCloseDatabase(){
ADOConn.close;
}

Response.Buffer=1;
Server.ScriptTimeout=99999;
//////////可修改以下参数////////////////
varbeginid=230;//开始ID
varendid=500;//结束ID
////////////////////////////////////////
vararr,tstr,tid,getdata;
varcountid=0;
Response.Write(开始采集:从+beginid+到+endid+<hr>);
Response.Flush;
OpenDatabase();
varre=newRegExp(<title>(.*?)-彩酷</title>,ig);

for(varfi=beginid;fi<(endid+1);fi++){
tid=String(fi);
getdata=ajaxRead(
if(arr=re.exec(getdata)!=null){
tstr=String(RegExp.$1);
if(tstr!=null&&tstr!=undefined&&tstr!=)
tstr=tstr.replace(,);
ADOConn.execute(INSERTINTOgetdata(title,tid)VALUES(+tstr+,+tid+));
Response.Write(tid+:+tstr+___>OK!<br>);
countid++;
Response.Flush
}
}
re.close;
CloseDatabase();
Response.Write(<hr>采集完毕!共录入数据+countid+条。);
%>


评论


亲,登录后才可以留言!