Skip to content

getUrls method for single CSSRule, not CSSStyleSheet? #16

Description

@vdmit

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions