0

I'm starting using the cssutils library and I want to do something like the lxml.html library function "iterlinks()", in a nutshell I just want to get all the links inside the css file. I thought on doing it myself but I dont know if this is well done:

sheet = cssutils.parseString("http://example.com/style.css")
links = []
for rule in sheet.cssRules:
    for child in rule.style.children():
        value = child.propertyValue
        for i in range(value.length):
            if isinstance(i, cssutils.css.URIValue):
                links.append(i)

I would like to know if there is a cleaner way to do it, even if there is an alternative library

1 Answer 1

2

cssutils has a method for this -- use getUrls

It will iterate over a rule, or over the the entire stylesheet, and return all of the urls that it finds.

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.