小偷,采集程序常用函数_ASP教程-查字典教程网
小偷,采集程序常用函数
小偷,采集程序常用函数
发布时间:2016-12-29 来源:查字典编辑
摘要://连接数据库functionconnOpen(DataBaseConnectStr){varconn=Server.CreateObjec...

<scriptlanguage="javascript"runat="server">

//连接数据库

functionconnOpen(DataBaseConnectStr){

varconn=Server.CreateObject("ADODB.Connection");

conn.Open(DataBaseConnectStr);

returnconn;

}

//利用AdoDb.Stream对象来读取指定格式的文本文件

functionreadFromTextFile(FileUrl,CharSet){

varstr;

varstm=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;

returnstr;

}

//利用AdoDb.Stream对象来写入指定格式的文本文件

functionwriteToTextFile(FileUrl,Str,CharSet){

varstm=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判断文件是否存在

functionisFileExist(FileUrl){

varFSO=Server.CreateObject("Scripting.FileSystemObject")

if(FSO.FileExists(Server.MapPath(FileUrl))){

returntrue;

}else{

returnfalse;

}

}

//利用fso写文件

functionCateFile(files,fbody){

varfs=Server.CreateObject("Scripting.FileSystemObject");

vara=fs.CreateTextFile(Server.mappath(files));

a.Write(fbody);

a.close();

}

//获取目标页面源代码

functiongetHTTPPage(url){

varHttp=Server.CreateObject("Microsoft.XMLHTTP");

Http.open("GET",url,false);

Http.send();

if(Http.readystate!==4){returnfalse;}

return(BytesToBstr(Http.responseBody,"GB2312"));

}

//编码

functionBytesToBstr(body,Cset){

varobjstream=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();

}

//获取完整连接地址

functionGetCompleteUrl(sources_url,get_url){

if(get_url.indexOf("http://")!=-1)returnget_url;

varcompleteUrl="";

varsources_url_arr=sources_url.split("/");

varget_url_arr=get_url.split("../");

for(vari=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];

returncompleteUrl;

}

</script>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新ASP教程学习
    热门ASP教程学习
    编程开发子分类