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:
fromcssutilsimportCSSParserfromcssutils.cssimportCSSStyleRulefromcssutils.cssimportCSSStyleSheetfromcssutilsimportgetUrlsparser=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?