I am experimenting with CSS files in Python to assist colour blind people. I need to get inside every selector block and change the 'background:' and 'color:'. I tried using CSS parsers like tinycss
but they are not concentrating on getting selectors.
Example input:
body {background:#fff; color:#ccc}
And output:
body {background:#000; color:#aaa}
try this:
http://cthedot.de/cssutils/
parser = CSSParser()
# optionally
parser.setFetcher(fetcher)
sheet = parser.parseFile('test1.css', 'ascii')
print sheet.cssText
it's pretty simple to use in css processing.
to work with selectors you could use cssutils.css.SelectorList
and cssutils.css.Selector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With