一段采集程序代码
时间:2021-09-06 09:01:30|栏目:ASP代码|点击: 次
<%@LANGUAGE="JScript" CODEPAGE="936"%>
<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+"条。");
%>
<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+"条。");
%>
上一篇:查看所有的Server Variables的环境变量
栏 目:ASP代码
本文标题:一段采集程序代码
本文地址:http://www.codeinn.net/misctech/172978.html