def get_ext(url): """Return the filename extension from url, or ''.""" parsed = urlparse(url) root, ext = splitext(parsed.path) return ext[1:] # or ext if you want the leading '.'