Created
March 17, 2016 07:14
-
-
Save dasdachs/38428ad8b0f4c57a83c9 to your computer and use it in GitHub Desktop.
Python - get URLs from CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_urls(css_file): | |
""" | |
Get all URLs from a CSS file with regex pattern matching. | |
URI's, like data URIs are ignored and URLs might be relative. | |
:param css_file: a string representing the CSS file (use open() | |
and read() or a request library to get the string) | |
:return: list with retrived urls | |
""" | |
import re | |
urls = re.findall(r'url\(["\']?(?P<url>[^"\'\)].*?)["\']?[\)]', css_file) | |
return urls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment