【发布时间】:2014-01-04 16:26:45
【问题描述】:
我正在尝试像这样解析 jquery 代码:(这是主要部分,但不是全部)
$("#column-wide").css({"background-color":"#eff6f9"});
$("#2626").css({"width":"300px"});
$("#2627").css({"width":"300px"});
$("#2628").css({"width":"300px"});
$("#2629").css({"width":"300px"});
$(".Country > label").css({"position":"relative", "left":"-20px", "top":0});
$("#2631").css({"position":"relative", "left":"-20px", "top":0, "width":128, "height":29});
$("#2633").css({"width":"300px"});
$("#2634").css({"width":"300px"});
// CONTACT INFO BELOW:
$("#2633").css({});
$("#2633").css({"position":"relative", "left":0, "top":0, "width":289, "height":19});
$("#2630").css({"position":"relative", "left":0, "top":0, "width":46, "height":19});
$("#2638").css({"width":"300px"});
$("#2639").css({"width":"300px"});
$(".Prefix").css({"display":"none", "visibility":""});
$(".Last_Name").css({"left":39, "top":3});
$("#2636").css({"position":"relative", "left":49, "top":1});
$("#2640").css({"position":"relative", "left":0, "top":0});
$("#2640").css({"width":"88px"});
$(".State > label").css({"position":"relative", "left":"-60px", "top":0});
$("#2641").css({"position":"relative", "left":"-116px", "top":0});
$("#2641").css({"width":"88px"});
$(".State > label").css({"left":"-121px"});
$("#2641").css({"left":"-161px", "width":98, "height":29});
$("#2637").css({"position":"relative", "left":"5px", "top":0});
$(".State > label").css({"left":"-109px"});
$("#2642").css({"width":"88px"});
$("#2643").css({"width":"88px"});
$(".Alternate_Phone").css({"left":"-129px"});
$(".State > label").css({"left":"-81px"});
$("#2643").css({"position":"relative", "left":"-32px", "top":0});
$(".UserAgreement label").css({"position":"relative", "left":0, "top":0, "width":419, "height":77});
像这样进入一行,只选择带有 .css 的行,没有别的:
$('head').append("<style> #2626 { width: 300px; } #2627 { width: 300px; } #2626 { width: 250px; height: 50px; } </style>");
我需要能够获取第一个 # 元素,所有带有 .css 的行,然后是变体,例如"width: 300px" 并将其放在如上所示的单行格式中。 我一直在尝试使用 bash 来做到这一点。
#!/bin/bash
echo Enter filename:
read fname
echo "#######"
while read line;do
echo -n "\$('head').append(\"<style> "
awk -F "[)(]" '/.css/{printf "%s %s ",$2,$4}' $fname|sed 's/\"//g;s/,/;/g'
echo -n "</style>\");"
done < $fname
echo "Total number of lines in file: $k"
【问题讨论】:
-
如果您在标题中说要使用 bash 或 perl,为什么这会被标记为“python”?
-
使用 python 也是可以接受的 - 很抱歉造成混乱!
-
它们来自哪里:#2626 { width: 250px;高度:50px; }
标签: jquery python parsing sed awk