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?
currently
getUrlsmethod could be applied toCSSStyleSheetobject only. Is there a simple way to get urls from single CSS rule?My workaround is like following:
but it seems to be a bit over-engineered. Is there a better/faster way?