最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP在线解压以及采集gzip压缩的页面的方法

日期:10-28    来源:中国设计秀    作者:cnwebshow.com

由于winrar的命令行工具不支持zip格式的文件,所以我选择了7z的命令行工具7za.exe,在百度搜索下就可以找到UN6中国设计秀
在使用下面的代码前把cmd.exe(windows文件夹下有)和7za.exe拷贝到asp程序目录UN6中国设计秀

代码(JScript格式)UN6中国设计秀
时间关系,并没有写更多的容错以及返回值问题UN6中国设计秀

function unZip(file){UN6中国设计秀
    //在线解压zip函数UN6中国设计秀
    //by fisker (http://ifisker.com lionkay@Gmail.com)UN6中国设计秀
    var objfso=Server.CreateObject("scripting.FileSystemObject");UN6中国设计秀
    var objWshShell=Server.CreateObject("Wscript.Shell");UN6中国设计秀
    var zipFile=Server.MapPath(file);UN6中国设计秀
    if(!objFso.FileExists(zipFile)) return false;UN6中国设计秀
    var runcmd=Server.MapPath("cmd.exe")+" /c "+Server.MapPath("7za.exe")+" x "+zipFile+" -y -o"+Server.MapPath("./");UN6中国设计秀
    var RetCode = objWshShell.Run(runcmd,1,true);UN6中国设计秀
    if(RetCode!=0)return false;UN6中国设计秀
    delete objWshShell;UN6中国设计秀
    delete objFso;UN6中国设计秀
}UN6中国设计秀

 UN6中国设计秀

关于gzip压缩页面的问题UN6中国设计秀
思路:用ServerxmlHTTP组件下载页面,保存为*.zip文件,解压文件,读取文件UN6中国设计秀
代码(JScript格式)UN6中国设计秀

function getGzipPage(url){UN6中国设计秀
    //Gzip格式页面采集程序UN6中国设计秀
    //by fisker (http://ifisker.com lionkay@gmail.com)UN6中国设计秀
    var fileStream;UN6中国设计秀
    var xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP");UN6中国设计秀
    xmlHttp.open("GET",url,false);UN6中国设计秀
    xmlHttp.send(null);UN6中国设计秀
    fileStream=xmlHttp.responseBody;UN6中国设计秀
    delete xmlHttp;UN6中国设计秀
    var objStream = Server.CreateObject("ADOD"+"B.Stream");UN6中国设计秀
    objStream.Type = 1;UN6中国设计秀
    objStream.Open();UN6中国设计秀
    objStream.write(fileStream);UN6中国设计秀
    objStream.SaveToFile(Server.MapPath("tmp.html.zip"),2);UN6中国设计秀
    objStream.Flush();UN6中国设计秀
    objStream.Close();UN6中国设计秀
    delete objStream;UN6中国设计秀
    unZip("tmp.html.zip");UN6中国设计秀
    var str=ReadFile("tmp.html");//ReadFile,deleteFile就是简单的文本读取和文件删除函数,未附代码UN6中国设计秀
    deleteFile("tmp.html.zip");UN6中国设计秀
    deleteFile("tmp.html");UN6中国设计秀
    return str;UN6中国设计秀
}UN6中国设计秀

作者:fiskerUN6中国设计秀

本文引用地址:/bc/article_46302.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明