CSS capture Download

Source: Internet
Author: User

Software application scope: See favorite pages, Save as words, and can not directly save the CSS referenced in the picture. Then there is the application of the software.
Highlights: Automatically match the relative path within the file, CSS image address value MD5 save, to avoid the duplication of files with the same name in different folders embarrassing
1. [Code]aauto Code

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 Collection Wizard"; border= "dialog Frame";p arent= ...)
Winform.add (
btndown={bottom=71;text= "Download"; 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 URL"; 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 Thanks for having you, Happy New Year!" ", 280);
Status.additem ("Author: Times network. Qq:87059222 ");

Assignment Test CSS Address
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 file address cannot be empty!") "," CSS Collection Wizard ");
return;
}
var cssfile = Winform.cssUrl.text;
var Tcsspath = Io.splitpath (cssfile);

Get current time
t_now=. Time.now ();
T_now.format= "%y year%M month%d day%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 File download error," + ErrMsg + "!) "," CSS Collection Wizard ");
return;
}
if (csscontent==null) {
Winform.msgbox ("CSS file content is empty or download exception!") "," CSS Collection Wizard ");
return;
}
var regexexpression = "Url\" ((. *?) \)";
For Strgmatchresult in String.gmatch (Csscontent, regexexpression) {
if (String.find (Strgmatchresult, ' data:image ') | | strgmatchresult== ' About:blank ') {
Temporarily not processing
} else {
Strgmatchresult = String.Replace (Strgmatchresult, "" "", "");
Handle relative path picture URLs
Imghttpfile = Inet.url.joinpath (Cssfile,strgmatchresult);
The image URL MD5 processing, prevent duplicate download and file name different download overwrite conflict, with MD5 value is unique.
StrGmatchResultMD5 = STRING.MD5 (imghttpfile,true);

Http://hi.bdimg.com/static/qhome/css/home/n0001/home_datauri.css?v=bbdea37b.css
For CSS inside the parameter picture file, separate the true suffix name. Have a better wording, please.
such as "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 {Monkey cartoon funny

ext = Tpath.ext;

}http://www.huiyi8.com/gaoxiaodonghua/xiyouji/

var savecssimgfilename = strGmatchResultMD5 + ext;

Csscontent = String.Replace (csscontent, ' <@ ' +strgmatchresult+ ' @> ', savecssimgfilename);
According to MD5 file name to determine not downloaded before downloading
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 + "| | | Error: "+ errmsg + ' \r\n\r ');
}
Win.delay (100);
}
}
}
String.save ("/data/" + Cssfolder + "/" + Cssfolder + ". css", csscontent);
Winform.richedit.appendText ("CSS and image download success, thanks for using!") "+ ' \ r \ n ');
}

Winform.show ()
Win.loopmessage ();

CSS capture Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.