def imageGrab(urlstring, filename): #returns the image url grabbed or False if none #get file handle to web page response = urllib.urlopen(urlstring) #get web page contents as string html = response.read() #close file handle response.close() images = imageURLFilter(html.split(), ".jpg") #bcolor.printBlue("image urls retrieved") #for i in images: # bcolor.printBlue(i) #no images found if not images: bcolor.printRed("No image to download.\n") return "" #404 for mangahere.com #if images[0][5:-1] == "http://m.mhcdn.net/media/images/404_img.jpg?v=297": #bcolor.printRed("Reached the end of the chapter.\n") #return "" #remove src=" and the trailing " part of the string #use as url and save to file named base.jpg im = urlFormat(images[0]) #bcolor.printBlue("Trying to grab image from: " + im) urllib.urlretrieve(im, filename + ".jpg") return im
import mangaDownloader import bcolor #test url1 404 testurl1 = "http://www.mangapanda.com/shingeki-no-kyojin/53/48" image = mangaDownloader.imageGrab(testurl1, "test1") if not image: bcolor.printGreen("Test 1 (404 handling) success!\n") else: bcolor.printRed("Test 1 (404 handling) failed!\n") #test url2 mangapanda testurl2 = "http://www.mangapanda.com/shingeki-no-kyojin/53/" image = mangaDownloader.imageGrab(testurl2, "test2") if image == "http://i13.mangapanda.com/shingeki-no-kyojin/53/shingeki-no-kyojin-4699239.jpg": bcolor.printGreen("Test 2 (mangapanda single image download) success!\n") else: bcolor.printRed("Test 2 (mangapanda single image download) failed!\n")