Skip to content
Advertisement

Extracting url from style: background-url: with beautifulsoup and without regex?

I have:

JavaScript

I want to get the url, however I don’t know how to do that without the use of regex. Is it even possible?

so far my solution with regex is:

JavaScript

Advertisement

Answer

You could try using the cssutils package. Something like this should work:

JavaScript

Although you are ultimately going to need to parse out the actual url this method should be more resilient to changes in the HTML. If you really dislike string manipulation and regex, you can pull the url out in this roundabout way:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement