2012-05-14 5 views
0

インポートされたCSSファイルで発生する幅の数をPythonで探したいと思います。Python:インポートされたCSSファイルからの幅の検索

私は私のpythonに新たなんだ

css = open("/Users/john/Work/html/Ribbon/header.css") 
    print(css.read()) 
    #output 

#back { 
    width: 680px; 
    height: 280px; 
    border: 2px solid #000; 
    margin: 100px auto; 
    background: url("background.png"); 
    position: relative; 
} 

#back ul { 
    margin-top: 115px; 
    margin-left: 80px; 
    width: 476px; 
    height: 39px; 
    border: 2px solid #b4c5cf; 
    background: #f3f8fa; 
} 

#back #topborder { 
    background: url("top_border.png"); 
    position: absolute; 
    width: 100%; 
    height: 23px; 

} 

#back #bottomborder { 
    background: url("bottom_border.png"); 
    width: 100%; 
    height: 23px; 
    bottom: 0; 
    position: absolute; 
} 

は、いくつかのより多くの方法を提案してください()関数ファイルを使用しています。 さらに手続きを進めてください。

ありがとうございました。

答えて

0

私はあなたが求めているものを100%わからないんだけど、あなたは、あなたが以下の(非常に簡単)メソッドを使用でき、あなたのCSSファイルでwidth:定義の数をカウントしようとしている場合:

count = 0 
with open('/Users/john/Work/html/Ribbon/header.css', 'r') as f: 
    for line in f: 
     if "width:" in line: 
      count+=1 
print("Found %d instances of 'width:'." % count) 
0

さまざまなCSSパーサーがあります。 Googleに「python css parser」を依頼してください。そのうちの1つを使用して、関連する属性を見つける/カウントするのが簡単になると確信しています。

関連する問題