小偷,采集程序常用函數(shù)
更新時(shí)間:2006年09月06日 00:00:00 作者:
<script language="javascript" runat="server">
//連接數(shù)據(jù)庫(kù)
function connOpen(DataBaseConnectStr){
var conn = Server.CreateObject("ADODB.Connection");
conn.Open(DataBaseConnectStr);
return conn;
}
//利用AdoDb.Stream對(duì)象來(lái)讀取指定格式的文本文件
function readFromTextFile(FileUrl,CharSet){
var str;
var stm = Server.CreateObject("adodb.stream");
stm.Type = 2;
stm.Mode = 3;
stm.Charset=CharSet;
stm.open;
stm.LoadFromFile(Server.MapPath(FileUrl));
str = stm.ReadText
stm.close;
return str;
}
//利用AdoDb.Stream對(duì)象來(lái)寫(xiě)入指定格式的文本文件
function writeToTextFile(FileUrl,Str,CharSet){
var stm = Server.CreateObject("adodb.stream");
stm.Type = 2;
stm.Mode = 3;
stm.Charset = CharSet;
stm.open;
stm.WriteText(Str);
stm.SaveToFile(Server.MapPath(FileUrl),2);
stm.flush;
stm.close;
}
//利用fso判斷文件是否存在
function isFileExist(FileUrl){
var FSO = Server.CreateObject("Scripting.FileSystemObject")
if(FSO.FileExists(Server.MapPath(FileUrl))){
return true;
}else{
return false;
}
}
//利用fso寫(xiě)文件
function CateFile(files,fbody){
var fs = Server.CreateObject("Scripting.FileSystemObject");
var a = fs.CreateTextFile(Server.mappath(files));
a.Write(fbody);
a.close();
}
//獲取目標(biāo)頁(yè)面源代碼
function getHTTPPage(url){
var Http= Server.CreateObject("Microsoft.XMLHTTP");
Http.open("GET",url,false);
Http.send();
if (Http.readystate!==4){return false;}
return(BytesToBstr(Http.responseBody,"GB2312"));
}
//編碼
function BytesToBstr(body,Cset){
var objstream = Server.CreateObject("adodb.stream");
objstream.Type = 1;
objstream.Mode =3;
objstream.Open();
objstream.Write = body;
objstream.Position = 0;
objstream.Type = 2;
objstream.Charset = Cset;
return(objstream.ReadText);
objstream.Close();
}
//獲取完整連接地址
function GetCompleteUrl(sources_url,get_url){
if(get_url.indexOf("http://")!=-1)return get_url;
var completeUrl="";
var sources_url_arr = sources_url.split("/");
var get_url_arr = get_url.split("../");
for(var i=0;i<sources_url_arr.length-get_url_arr.length;i++){
completeUrl += sources_url_arr[i] + "/";
}
completeUrl += get_url_arr[get_url_arr.length-1];
return completeUrl;
}
</script>
//連接數(shù)據(jù)庫(kù)
function connOpen(DataBaseConnectStr){
var conn = Server.CreateObject("ADODB.Connection");
conn.Open(DataBaseConnectStr);
return conn;
}
//利用AdoDb.Stream對(duì)象來(lái)讀取指定格式的文本文件
function readFromTextFile(FileUrl,CharSet){
var str;
var stm = Server.CreateObject("adodb.stream");
stm.Type = 2;
stm.Mode = 3;
stm.Charset=CharSet;
stm.open;
stm.LoadFromFile(Server.MapPath(FileUrl));
str = stm.ReadText
stm.close;
return str;
}
//利用AdoDb.Stream對(duì)象來(lái)寫(xiě)入指定格式的文本文件
function writeToTextFile(FileUrl,Str,CharSet){
var stm = Server.CreateObject("adodb.stream");
stm.Type = 2;
stm.Mode = 3;
stm.Charset = CharSet;
stm.open;
stm.WriteText(Str);
stm.SaveToFile(Server.MapPath(FileUrl),2);
stm.flush;
stm.close;
}
//利用fso判斷文件是否存在
function isFileExist(FileUrl){
var FSO = Server.CreateObject("Scripting.FileSystemObject")
if(FSO.FileExists(Server.MapPath(FileUrl))){
return true;
}else{
return false;
}
}
//利用fso寫(xiě)文件
function CateFile(files,fbody){
var fs = Server.CreateObject("Scripting.FileSystemObject");
var a = fs.CreateTextFile(Server.mappath(files));
a.Write(fbody);
a.close();
}
//獲取目標(biāo)頁(yè)面源代碼
function getHTTPPage(url){
var Http= Server.CreateObject("Microsoft.XMLHTTP");
Http.open("GET",url,false);
Http.send();
if (Http.readystate!==4){return false;}
return(BytesToBstr(Http.responseBody,"GB2312"));
}
//編碼
function BytesToBstr(body,Cset){
var objstream = Server.CreateObject("adodb.stream");
objstream.Type = 1;
objstream.Mode =3;
objstream.Open();
objstream.Write = body;
objstream.Position = 0;
objstream.Type = 2;
objstream.Charset = Cset;
return(objstream.ReadText);
objstream.Close();
}
//獲取完整連接地址
function GetCompleteUrl(sources_url,get_url){
if(get_url.indexOf("http://")!=-1)return get_url;
var completeUrl="";
var sources_url_arr = sources_url.split("/");
var get_url_arr = get_url.split("../");
for(var i=0;i<sources_url_arr.length-get_url_arr.length;i++){
completeUrl += sources_url_arr[i] + "/";
}
completeUrl += get_url_arr[get_url_arr.length-1];
return completeUrl;
}
</script>
相關(guān)文章
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序入門(mén)教程
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序入門(mén)教程...2006-06-06
網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略
網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略...2006-08-08
實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序
實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序...2007-03-03
網(wǎng)站生成靜態(tài)頁(yè)面攻略2:數(shù)據(jù)采集
網(wǎng)站生成靜態(tài)頁(yè)面攻略2:數(shù)據(jù)采集...2006-08-08
利用MSXML2.XmlHttp和Adodb.Stream采集圖片
asp下經(jīng)常用來(lái)采集的兩個(gè)組件結(jié)合使用例子2008-05-05

