利用浏览器调试功能 计算 百度网盘 文件数量 V2
生活随笔
收集整理的這篇文章主要介紹了
利用浏览器调试功能 计算 百度网盘 文件数量 V2
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近需要統(tǒng)計(jì)百度網(wǎng)盤里文件的數(shù)量,百度網(wǎng)盤又沒有提供這樣的功能,因此之前自己寫了段腳本進(jìn)行查驗(yàn),見《利用瀏覽器調(diào)試功能 計(jì)算 百度網(wǎng)盤》。之后發(fā)現(xiàn)每個(gè)目錄最多文件數(shù)只有1000,因此研究了哈百度的接口,重新對(duì)腳本進(jìn)行了修改。具體見代碼:
/******************** *百度文件數(shù)量統(tǒng)計(jì) V2 *2018.06.15 *Jackie ********************//************ *百度查詢接口 http://pan.baidu.com/api/list? dir= //查詢目錄 &num=100000 //分頁大小 最大支持99999999999999 默認(rèn)1000 &page=1 //頁碼 &order=time //排序?qū)傩?&desc=1 //排序順序 &clienttype=0 &showempty=0 ************/var root = "";//指定目錄,空取當(dāng)前目錄 var maxPageSize=99999999999999; //最多支持這么多,超過此值無效 var dskApi="https://pan.baidu.com/api/list?&num="+maxPageSize+"&page=1&dir="; var totalCount = 0; var startTime = new Date(); function timeSpan(stime, etime) {var usedTime = etime - stime;var days = Math.floor(usedTime / (24 * 3600 * 1000));var leave1 = usedTime % (24 * 3600 * 1000);var hours = Math.floor(leave1 / (3600 * 1000));var leave2 = leave1 % (3600 * 1000);var minutes = Math.floor(leave2 / (60 * 1000));var leave3 = leave2 % (60 * 1000);var seconds = Math.round(leave3 / 1000);var time ="";if(days>0){time+=days+"天";}if(hours>0){time+=hours+"小時(shí)";}if(minutes>0){time+=minutes+"分鐘";}time+=seconds+"秒";return time; } (function($){$.getUrlParam = function (name) {var search = document.location.hash;var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");var matcher = pattern.exec(search);var items = null;if (null != matcher) {try {items = decodeURIComponent(decodeURIComponent(matcher[1]));} catch (e) {try {items = decodeURIComponent(matcher[1]);} catch (e) {items = matcher[1];}}}return items;} })(jQuery);if(root=="") {root=$.getUrlParam("path"); }function GetFilesCount(fileLists) {var count=0;var fl=fileLists.length;for (var index=0; index<fl; index++) { (function(index) { var file=fileLists[index];if(file.isdir==0){count++;totalCount++;}else if(file.isdir==1){count=count+GetDirFilsCount(file.path);}})(index); } return count; }function GetDirFilsCount(dirName) {var dfCount=0;$.ajax({url: dskApi+''+dirName,type: 'get',async: true,//true 異步,false 同步success: function(data) {var fileLists = data.list;dfCount=GetFilesCount(fileLists); console.log(decodeURIComponent(dirName)+":"+dfCount);console.log("統(tǒng)計(jì)目錄為:“"+decodeURIComponent(root)+"” 當(dāng)前計(jì)算總數(shù):"+totalCount+" 用時(shí):" +timeSpan(startTime, new Date()));}});return dfCount; }GetDirFilsCount(root);提示:由于百度服務(wù)器或者接口可能不穩(wěn)定,會(huì)造成查詢不準(zhǔn)確,數(shù)據(jù)僅供參考。
文件多的話,查詢比較耗時(shí),同步的準(zhǔn)確率比異步要高,但更耗時(shí)。
如圖,用了半個(gè)小時(shí)才統(tǒng)計(jì)了15W左右的數(shù)據(jù),據(jù)百度稱俺的文件數(shù)超過了500W,哈哈。
總結(jié)
以上是生活随笔為你收集整理的利用浏览器调试功能 计算 百度网盘 文件数量 V2的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用浏览器调试功能 计算 百度网盘 文件
- 下一篇: 2017年html5行业报告,云适配发布