标题: [文本处理] 【已解决】求一个提取css的批处理文件 [打印本页]
作者: linjuming 时间: 2009-5-19 16:43 标题: 【已解决】求一个提取css的批处理文件
熟悉网页设计的人应该知道什么是css,我想通过在一个index.css文件中提取其中的几条标签,请问怎么做,我不会批处理,希望老哥们帮忙看看。
index.css中的代码如下:- /* ::::: http://www.google.com/cse/api/branding.css ::::: */
-
-
-
-
- body {margin: 0pt;
- padding: 0pt;
- background: rgb(248, 248, 248) none repeat scroll 0% 0%;
- font-family: arial,verdana,sans-serif;
- font-size: 76%;
- color: rgb(0, 0, 0);
- text-align: center;}
-
- a, a:visited {color: rgb(0, 68, 136);
- text-decoration: none;}
-
- a:hover {text-decoration: underline;}
-
- pre {font-size: 11px;}
-
- code {font-size: 12px;}
-
- .hiddenfromview {display: none;}
-
- #wrapper {margin: 0pt auto;
- width: 1025px;
- text-align: left;}
-
- #topad {background: rgb(248, 248, 248) none repeat scroll 0% 0%;
- height: 70px;
- margin-top: 10px;}
-
- #topad img {display: block;
- float: left;}
-
- #topad .adLeft {padding: 5px 0pt;
- float: left;}
-
- #topad .adRight {padding: 5px 0pt;
- float: right;}
-
- #topindexad {background: rgb(248, 248, 248) none repeat scroll 0% 0%;
- height: 70px;
- margin-top: 10px;}
-
- #topindexad div {float: left;}
-
- #topindexad img {display: block;
- float: left;}
-
- #header {background: transparent url('bar45.gif') no-repeat scroll 0% 0%;
- width: 1025px;
- height: 80px;
- position: relative;}
-
- #logo {padding-left: 15px;
- height: 45px;}
-
- #logo h1 {margin: 0pt;
- overflow: hidden;
- height: 45px;
- font-size: 26px;
- font-family: "times new roman",serif;
- line-height: 38px;
- float: left;}
-
- #logo h1 a {color: rgb(0, 0, 0);}
-
- #logo h2 {margin: 0pt;
- overflow: hidden;
- height: 45px;
- font-size: 22px;
- font-family: "times new roman",serif;
- font-weight: normal;
- line-height: 41px;
- color: rgb(238, 238, 238);
- padding-left: 3px;}
-
- #logo h2 a {color: rgb(255, 255, 255);}
-
- #logo a:hover {text-decoration: none;}
-
- #logo h3 {display: none;}
-
- #toplink {background: transparent url('sub_bar.gif') no-repeat scroll 0% 0%;
- width: 1025px;
- height: 25px;
- position: absolute;
- top: 50px;
- left: 0pt;}
-
- #toplink ul {margin: 0pt;
- padding: 0pt;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;
- position: absolute;
- right: 0pt;}
-
- #toplink ul li {float: left;
- margin-right: 10px;
- font-size: 9px;
- line-height: 25px;
- color: rgb(0, 153, 204);}
-
- #toplink ul li a {font-size: 9px;
- line-height: 25px;
- color: rgb(68, 68, 68);
- text-decoration: none;}
-
- #toplink ul li a:hover {text-decoration: underline;
- color: rgb(0, 153, 204);}
-
- #toplink ul li a img {border: 0pt none ;
- padding-top: 4px;}
-
- #botlink {width: 360px;
- height: 25px;
- position: absolute;
- top: 50px;
- left: 0pt;}
-
- #botlink ul {margin: 0pt;
- padding: 0pt;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;}
-
- #botlink ul li {float: left;
- margin-left: 10px;
- font-size: 9px;
- line-height: 25px;
- color: rgb(136, 136, 136);}
-
- #botlink ul li a {font-size: 9px;
- line-height: 25px;
- color: rgb(68, 68, 68);
- text-decoration: none;}
-
- #botlink ul li a:hover {text-decoration: underline;
- color: rgb(0, 136, 204);}
-
- #midlink {width: 600px;
- height: 50px;
- position: absolute;
- top: 0pt;
- left: 150px;}
-
- #midlink ul {margin: 0pt;
- padding: 0pt;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;}
-
- #midlink ul li {float: left;
- font-size: 14px;
- line-height: 36px;
- color: rgb(255, 255, 255);}
-
- #midlink ul li a {padding: 0pt 10px;
- font-size: 13px;
- line-height: 40px;
- color: rgb(255, 255, 255);
- text-decoration: none;
- font-weight: bold;}
-
- #midlink ul li a:hover {color: rgb(51, 51, 85);}
-
- #midlink ul li a.chosen {color: rgb(0, 0, 0);}
-
- #showcase {width: 1025px;
- height: auto;}
-
- img.slogan {background: transparent url('pc2.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.faq {background: transparent url('pc3.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.contact {background: transparent url('contact.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.privacy {background: transparent url('privacy.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.access {background: transparent url('access.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.support {background: transparent url('support.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.map {background: transparent url('map.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.advertise {background: transparent url('advertise2.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- img.oops {background: transparent url('oops.jpg') repeat scroll 0% 0%;
- display: block;
- float: left;}
-
- #info {border: 1px solid rgb(221, 221, 221);
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- width: 750px;
- float: left;}
-
- #info2 {width: 750px;
- float: left;}
-
- #info2 h2 {margin: 0pt;
- padding: 10px 0pt 0pt 10px;
- font-size: 15px;
- color: rgb(17, 85, 17);}
-
- #info p {line-height: 1.5em;}
-
- #info p.info {margin-left: 10px;}
-
- #info h2 {margin: 0pt;
- padding: 10px 0pt 5px 10px;
- font-size: 15px;
- color: rgb(17, 85, 17);}
-
-
- .box250 {padding: 0pt 0pt 15px;
- background: transparent url('box_base.gif') no-repeat scroll left bottom;
- width: 250px;
- margin-bottom: 10px;}
-
- .box250 h3 {margin: 0pt;
- padding: 0pt 15px;
- background: transparent url('box.gif') repeat scroll 0% 0%;
- height: 30px;
- line-height: 30px;
- color: rgb(51, 51, 51);
- font-size: 12px;}
-
- .box250 ul {border-style: solid;
- border-color: rgb(216, 217, 218);
- border-width: 0pt 1px;
- margin: 0pt;
- padding: 15px 14px 0pt;
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;
- width: 220px;
- height: auto;}
-
- .box250 ul li {border-bottom: 1px solid rgb(240, 240, 240);
- padding: 2px 0pt;
- text-decoration: none;
- color: rgb(68, 68, 68);
- font-size: 11px;
- word-spacing: -1px;}
-
- .box250 ul li a {text-decoration: none;
- color: rgb(0, 68, 136);
- font-size: 12px;
- font-weight: bold;}
-
- .box250 ul li a:hover {text-decoration: underline;}
-
- .box250 p {border-style: solid;
- border-color: rgb(216, 217, 218);
- border-width: 0pt 1px;
- margin: 0pt;
- padding: 15px 14px 0pt;
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- width: 220px;
- line-height: 1.3em;
- font-size: 11px;
- color: rgb(68, 68, 68);}
-
- .box250 dl {border-style: solid;
- border-color: rgb(216, 217, 218);
- border-width: 0pt 1px;
- margin: 0pt;
- padding: 0pt 14px;
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;
- width: 220px;}
-
- .box250 dt {margin: 0pt;
- padding: 10px 0pt;
- clear: left;
- font-size: 12px;
- font-weight: bold;
- color: rgb(17, 85, 17);}
-
- .box250 dd {border-bottom: 1px solid rgb(240, 240, 240);
- margin: 0pt;
- padding: 3px 0pt;
- font-size: 11px;
- line-height: 1.2em;
- color: rgb(68, 68, 68);}
-
- .box250 dd a {display: block;
- color: rgb(0, 68, 136);
- text-decoration: none;
- width: 220px;
- font-size: 12px;}
-
- .box250 dd a em {color: rgb(102, 102, 102);
- float: right;
- font-style: normal;
- font-size: 11px;}
-
- .box250 dd a:hover {color: rgb(0, 136, 204);
- text-decoration: none;}
-
- .box250 table caption {margin: 0pt;
- padding: 0pt;
- background: transparent url('box.gif') repeat scroll 0% 0%;
- width: 250px;
- height: 30px;
- line-height: 30px;
- color: rgb(51, 51, 51);
- font-size: 12px;
- text-align: left;
- text-indent: 15px;
- font-weight: bold;}
-
- .box250 table {border-style: solid;
- border-color: rgb(216, 217, 218);
- border-width: 0pt 1px;
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- width: 250px;}
-
- .box250 table th {padding-top: 5px;
- text-indent: 5px;
- color: rgb(17, 85, 17);}
-
- .box250 table td {text-indent: 5px;
- color: rgb(68, 68, 68);}
-
- .box250 table tfoot td {text-align: center;
- color: rgb(102, 102, 102);
- font-size: 11px;
- padding-top: 10px;}
-
- .box250 form {margin: 0pt;}
-
- .box250 a.bannerad img {display: block;
- padding-bottom: 4px;}
-
- .plain250 {padding: 0pt 0pt 15px;
- background: transparent url('plain250.gif') no-repeat scroll left bottom;
- width: 250px;
- margin-bottom: 10px;}
-
- .plain250 div {background: transparent url('plain250.gif') no-repeat scroll left top;
- width: 250px;
- text-align: center;}
-
- .plain250 ul {border-style: solid;
- border-color: rgb(216, 217, 218);
- border-width: 0pt 1px;
- margin: 0pt;
- padding: 0pt 14px;
- background: rgb(255, 255, 255) none repeat scroll 0% 0%;
- list-style-type: none;
- list-style-image: none;
- list-style-position: outside;
- width: 220px;
- height: auto;}
-
- .plain250 ul li {border-bottom: 1px solid rgb(240, 240, 240);
-
-
-
- padding: 2px 0pt;
- text-decoration: none;
- color: rgb(68, 68, 68);
- font-size: 11px;
- word-spacing: -1px;
- text-align: left;}
-
- .plain250 ul li a {text-decoration: none;
- color: rgb(0, 68, 136);
- font-size: 12px;
- font-weight: bold;}
-
- .plain250 ul li a:hover {text-decoration: underline;}
复制代码
我想提取其中几条我需要的标签,条件文本 rule.txt 内容如下:- "file:///F:/ScrapBook/data/20090413141615/index.css","file:///F:/ScrapBook/data/20090518222439/index.css"
- "No used selectors","14 used selectors:"
- ,
- ,body
- ,a
- ,a:visited
- ,a:hover
- ,#wrapper
- ,#content
- ,#right_column
- ,.box250
- ,.box250 dl
- ,.box250 dt
- ,.box250 dd
- ,.box250 dd a
- ,.box250 dd a em
- ,.box250 dd a:hover
复制代码
通过双击批处理文件后,得到一个result.txt文件内容如下:- a, a:visited {color: rgb(0, 68, 136);
- text-decoration: none;}
-
- a:hover {text-decoration: underline;}
-
- ......
-
- .box250 {padding: 0pt 0pt 15px;
- background: transparent url('box_base.gif') no-repeat scroll left bottom;
- width: 250px;
- margin-bottom: 10px;}
-
- .......
复制代码
[ 本帖最后由 Batcher 于 2009-5-22 22:15 编辑 ]
作者: namejm 时间: 2009-5-19 18:36
请用文字描述依照什么规律提取什么样的字符串,而不应只给出原始代码、rule.txt文件及最终结果——试问,除了你自己之外,有谁能真正明白其中的转化规律?
作者: linjuming 时间: 2009-5-19 19:01
对不起,之前说的不太清楚,现在加上了图片说明,应该好理解一点。
作者: namejm 时间: 2009-5-19 20:44
请先把 index.css 中MAC风格的换行符CR换成Windows风格的回车换行符CR+LF,再使用如下代码试试:- @echo off
- cd.>result.txt
- setlocal enabledelayedexpansion
-
- for /f "skip=3 delims=," %%i in (rule.txt) do (
- for /f "delims=:" %%j in ('findstr /bnc:"%%i {" index.css') do (
- call :get %%j
- )
- )
- start result.txt
- exit
-
- :get
- set /a num=%1-1
- echo.>>result.txt
- for /f "skip=%num% delims=" %%i in (index.css) do (
- (echo %%i)>>result.txt
- set "str=%%i"
- if "!str:~-1!"=="}" goto :eof
- )
- goto :eof
复制代码
作者: linjuming 时间: 2009-5-19 21:30
管理员飞扬哥,你太狠了,这么难的功能你都能写出来,佩服!!
太谢谢拉,我把帖子发了好几个论坛,没人理睬,或者说是太难,就你好人,好感动啊!!
祝愿批处理之家越办越好,成为中国最top的程序家园。
作者: namejm 时间: 2009-5-19 22:08
网上有这样的说法:问题能否得到解决,一方面取决于问题的难度,另一方面,还取决于你的提问方式及态度。具体到你这个帖子,一是因为问题有一定难度,另一方面,还在于你的描述太模糊,别人无法理解其宗的转换规律,所以会无人理睬。
题目的难度我们都没法控制,我们能控制的,就是我们的描述,不要让别人看着我们的描述,越来越头晕,人为地增加了不必要的难度,一定要确保我们的真实意图能清晰地传达给别人。
呵呵,啰啰嗦搜说了一大堆,就是希望以后能注意描述的清晰准确,以方便别人理解
最后,对你的祝福表示感谢,最top不敢奢望,但是,做最好的批处理论坛,则是我们所孜孜以求的。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |