標籤:winform style http io color ar os 使用 sp
軟體應用範圍: 看到喜歡的網頁,另存新檔的話,並不能直接儲存css中引用的圖片。 那麼就有了本軟體的用武之地。
亮點:自動匹配檔案內的相對路徑、css內圖片地址值md5儲存,用來避免不同檔案夾同名檔案的重複尷尬
1. [代碼]AAuto 代碼
import win.ui;
import inet.url;
import inet.whttp
import string.md5;
import web.form;
import fsys;
import win.ui.statusbar;
/*DSG{{*/
winform = ..win.form( right=587;bottom=400;max=false;text="CSS採集精靈";border="dialog frame";parent=...)
winform.add(
btnDown={ bottom=71;text="下載";left=492;top=12;z=4;right=580;cls="button" };
richedit={ vscroll=1;right=580;left=8;multiline=1;top=80;z=3;bottom=372;edge=1;cls="richedit" };
groupbox={ bottom=67;right=482;left=7;top=7;z=1;text="CSS HTTP網址";edge=1;cls="groupbox" };
cssUrl={ bottom=55;right=471;left=14;top=26;z=2;edge=1;cls="edit" }
)
/*}}*/
status = win.ui.statusbar(winform);
status.addItem(" AAuto 感謝有你,新年快樂!",280);
status.addItem(" Author:時代網路。QQ:87059222 ");
// 賦值測試css地址
winform.cssUrl.text = "http://www.aau.cn/data/cache/style_1_common.css?U0g";
winform.btnDown.oncommand = function(id,event){
if(winform.cssUrl.text == ""){
winform.msgbox("CSS檔案地址不可為空!","CSS採集精靈");
return ;
}
var cssFile = winform.cssUrl.text;
var tCssPath = io.splitpath(cssFile);
//擷取目前時間
t_now=..time.now();
t_now.format=" %Y年%m月%d日 %H-%M-%S";
t_now = tostring(t_now);
var cssFolder = string.replace(tCssPath.name,"[&%?]","_") + t_now;
if(!io.exist("/data/" + cssFolder) ){
fsys.createDir("/data/" + cssFolder)
}
var whttp = inet.whttp();
cssContent,errmsg = whttp.get(cssFile);
if(errmsg != null){
winform.msgbox("CSS檔案下載出現錯誤," + errmsg + "!","CSS採集精靈");
return ;
}
if (cssContent==null){
winform.msgbox("CSS檔案內容為空白或者下載異常!","CSS採集精靈");
return ;
}
var regexExpression = "url\((.*?)\)";
for strGmatchResult in string.gmatch( cssContent, regexExpression ){
if(string.find(strGmatchResult,‘data:image‘) || strGmatchResult==‘about:blank‘){
//暫不處理
} else {
strGmatchResult = string.replace(strGmatchResult,"""","");
// 處理相對路徑圖片網址
imghttpFile = inet.url.joinpath(cssFile,strGmatchResult);
// 將圖片網址md5處理,防止重複下載以及檔案同名不同參下載覆蓋衝突,用md5取值都是唯一了。
strGmatchResultMD5 = string.md5(imghttpFile,true);
// http://hi.bdimg.com/static/qhome/css/home/n0001/home_datauri.css?v=bbdea37b.css
// 針對css內 帶參數圖片檔案,分離出真是尾碼名。有更好的寫法請指點哦
// 如 "tpl_n0001_theme_001_background.jpg?v=30ab89f5.gif";
var tpath = io.splitpath(strGmatchResult);
var file = tpath.file;
if(string.find(file,"?")){
ext = io.splitpath(string.split(file,‘?‘)[1]).ext;
}else {西遊記動畫片搞笑
ext = tpath.ext;
}http://www.huiyi8.com/gaoxiaodonghua/xiyouji/
var saveCssImgFileName = strGmatchResultMD5 + ext;
cssContent = string.replace(cssContent,‘<@‘+strGmatchResult+‘@>‘,saveCssImgFileName);
// 根據md5檔案名稱判斷沒下載過才下載
if (!io.exist("/data/" + cssFolder + "/" + saveCssImgFileName)) {
winform.richedit.appendText(imghttpFile + " ||| " + saveCssImgFileName + ‘\r\n\r‘);
imgData,errmsg = whttp.get(imghttpFile);
if(errmsg == null){
string.save("/data/" + cssFolder + "/" + saveCssImgFileName ,imgData);
}else{
winform.richedit.appendText(imghttpFile + " ||| 錯誤:" + errmsg + ‘\r\n\r‘);
}
win.delay(100);
}
}
}
string.save("/data/" + cssFolder + "/" + cssFolder + ".css" ,cssContent);
winform.richedit.appendText("CSS及圖片下載成功,感謝使用!" + ‘\r\n‘);
}
winform.show()
win.loopMessage();
css 採集下載