0

I need to parse apart CSS using Python 2.7, but only looking for image requests within url(), such as:

background:url(/images/myimg.jpg)

Since the only thing I'm concerned about are values within url(), I don't need a large CSS parser to break apart every property within the CSS rules (and I'm not really seeing any that can correctly get the url() values anyways).

So since this will be custom code, what's the best method to break apart a large string of a CSS rules and gather each of the url() values into a list?

Below is what I'm hoping to get, and as fast and efficiently as possible (especially if the css file is 80K or more)

css = "body { background:url(/image/body-bg.png) } #content { background-image:url('../graphics/content-bg.jpg') }"

... magic goes here...

urls = [ '/image/body-bg.png', '../graphics/content-bg.jpg' ]

1 Answer 1

2

cssutils.getUrls

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.