cssutils
cssutils copied to clipboard
getUrls method for single CSSRule, not CSSStyleSheet?
currently getUrls method could be applied to CSSStyleSheet object only. Is there a simple way to get urls from single CSS rule?
My workaround is like following:
from cssutils import CSSParser
from cssutils.css import CSSStyleRule
from cssutils.css import CSSStyleSheet
from cssutils import getUrls
parser = CSSParser()
style = parser.parseStyle(cssText="height:450px; background-image: url('https://example.com/image.png');")
rule = CSSStyleRule(selectorText="html", style=style)
css = CSSStyleSheet()
css.add(rule)
print(list(getUrls(css)))
but it seems to be a bit over-engineered. Is there a better/faster way?
I'm not particularly familiar with the implementation, so I don't have a good answer to your question. I hope someone else does or maybe you can dive into the code and find your own answer. I'd be happy to consider patches that would make the usage easier.