From 4b3dd00086c26f1faa9f05dd45fd9a908cf903dd Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Wed, 5 Jul 2017 00:15:43 +0200 Subject: [PATCH] Do more checks before jumping to relinking. --- macli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/macli.py b/macli.py index f0a7c9e..e3d595e 100644 --- a/macli.py +++ b/macli.py @@ -52,6 +52,9 @@ def relink_css(content, base_url, directory='styles'): def relink_images(content, base_url, directory='images'): os.makedirs(directory, exist_ok=True) for image in content.find_all('img'): + if 'src' not in image.attrs: + continue + src = urllib.parse.urljoin(base_url, image['src'], allow_fragments=False) name = hashlib.sha1(src.encode()).hexdigest() + '.' + get_extension(src) @@ -67,6 +70,9 @@ def relink_images(content, base_url, directory='images'): def relink_scripts(content, base_url, directory='scripts'): os.makedirs(directory, exist_ok=True) for script in content.find_all('script'): + if 'src' not in script.attrs: + continue + href = urllib.parse.urljoin(base_url, script['src'], allow_fragments=False) name = hashlib.sha1(href.encode()).hexdigest() + '.' + get_extension(href)