From e75ce42e12fb418648e7518a62493b93162f2e68 Mon Sep 17 00:00:00 2001 From: Lorenzo Di Fuccia Date: Mon, 15 Jan 2018 11:26:30 +0100 Subject: [PATCH] Bug fix for `link_replace` empty arg --- safaribooks.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/safaribooks.py b/safaribooks.py index 315dd08..b584e2f 100644 --- a/safaribooks.py +++ b/safaribooks.py @@ -475,17 +475,19 @@ def get_html(self, url): return root def link_replace(self, link): - if link[0] == "/" and ("cover" in link or "images" in link or "graphics" in link - or link[-3:] in ["jpg", "peg", "png", "gif"]): - if link not in self.images: - self.images.append(link) - self.display.log("Crawler: found a new image at %s" % link) + if link: - image = link.split("/")[-1] - return "Images/" + image + if link[0] == "/" and ("cover" in link or "images" in link or "graphics" in link + or link[-3:] in ["jpg", "peg", "png", "gif"]): + if link not in self.images: + self.images.append(link) + self.display.log("Crawler: found a new image at %s" % link) - elif link[0] not in ["/", "h"]: - return link.replace(".html", ".xhtml") + image = link.split("/")[-1] + return "Images/" + image + + elif link[0] not in ["/", "h"]: + return link.replace(".html", ".xhtml") return link