Skip to content

Commit

Permalink
Bug fix for link_replace empty arg
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzodifuccia committed Jan 15, 2018
1 parent 22a8791 commit e75ce42
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e75ce42

Please sign in to comment.