lxml.html を使用して html ファイルを解析していますが、スタイルシートでセレクターとして使用される HTML クラス、つまり['c1','c2','c3','c4','c5','c6']
対応するスタイル情報を取得する必要があります。
スタイルセクションを文字列として抽出し、それを使用して解析しようとしcssutils.parseString
ましたが、最終的には次のようになります。
ERROR CSSStyleRule: No start { of style declaration found: u'<style type="text/css"> ' [1:28: ;]
ERROR Selector: Unexpected CHAR. [1:1: <]
ERROR Selector: Unexpected CHAR. [1:12: =]
ERROR Selector: Unexpected STRING. [1:13: "text/css"]
ERROR Selector: Unexpected CHAR. [1:24: &]
ERROR SelectorList: Invalid Selector: <style type="text/css">
ERROR CSSStyleRule: No style declaration or "}" found: u'<style type="text/css"> '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [2:47: ;]
ERROR Selector: Unexpected CHAR. [2:43: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [3:33: ;]
ERROR Selector: Unexpected CHAR. [3:29: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [4:32: ;]
ERROR Selector: Unexpected CHAR. [4:28: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [5:34: ;]
ERROR Selector: Unexpected CHAR. [5:30: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [6:34: ;]
ERROR Selector: Unexpected CHAR. [6:30: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u' ' [7:53: ;]
ERROR Selector: Unexpected CHAR. [7:49: &]
ERROR SelectorList: Invalid Selector: 
ERROR CSSStyleRule: No style declaration or "}" found: u' '
ERROR CSSStyleRule: No start { of style declaration found: u'</style>' [8:13: ]
ERROR Selector: Unexpected CHAR. [8:5: <]
ERROR Selector: Unexpected CHAR. [8:6: /]
ERROR Selector: Cannot end with combinator: </style>
ERROR SelectorList: Invalid Selector: </style>
ERROR CSSStyleRule: No style declaration or "}" found: u'</style>'
<cssutils.css.CSSStyleSheet object encoding='utf-8' href=None media=None title=None namespaces={} at 0x308ca90>
どうすればこれを解決できますか?
<style type="text/css">
p.c6 {font-weight: bold; text-align: left}
p.c5 {font-weight: bold}
p.c4 {text-align: left}
td.c3 {font-weight: bold}
p.c2 {text-align: center}
p.c1 {font-weight: bold; text-align: center}
</style>