0

I am trying to get all the urls of images that are used within a css file. For example this is part of my css file:

sitewrap {
    width: 890px;
    margin: 0 auto;
    background: #ffffff url(../images/bg_sitewrap.gif) repeat-y;
}

How can receive just the ../images/bg_sitewrap.gif section of it, in python preferably?

Thanks in advance for the assistance!

0

1 Answer 1

2

You could try using re.findall here:

css = """sitewrap {
    width: 890px;
    margin: 0 auto;
    background: #ffffff url(../images/bg_sitewrap.gif) repeat-y;
}"""

urls = re.findall(r'\burl\((.*?)\)', css)
print(urls)  # ['../images/bg_sitewrap.gif']

This answer assumes that you would want to capture every instance of url(...) in your CSS script. If not, then you might need to use a CSS parser/library, before perhaps using regex later in the pipeline to find the URLs.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.