Protocol_

Explosm Comics Downloader :3

Mar 20th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. """
  4. explosm.py
  5. Coded by Donny
  6. Can be used for downloading Cynadie & Happiness comics
  7. """
  8.  
  9. import urllib, re, os
  10.  
  11. class Downloader:
  12.     def __init__(self):
  13.         print """
  14.             ###########################
  15.             #Explosm comics downloader#
  16.             ##########################
  17.              """
  18.         self.comic_url = "http://explosm.net/comics/15/"
  19.         self. run = True
  20.         while self.run:
  21.             self.PicandPage(self.comic_url)
  22.        
  23.     def PicandPage(self, url):
  24.         self.arr = self.getHTML(url)
  25.         try:
  26.             self.split = self.find(self.arr, "http://www.explosm.net/db/files/").split('"')
  27.         except:
  28.             pass
  29.        
  30.         try:
  31.             print "Downloading picture : %s" % (self.split[0])
  32.             self.download(self.split[0])
  33.         except:
  34.             print "Couldn't download picture"
  35.  
  36.         try:
  37.             print "Finding link of next page.."
  38.             self.page = self.find(self.arr, "<a rel=\"next\" href=").split('"')
  39.             self.comic = self.page[3].split('/')
  40.             self.comic_url = self.comic[2]
  41.             print "New comic's url : %s" % (self.comic_url)
  42.             self.PicandPage("http://explosm.net/comics/"+self.comic_url+"/")
  43.            
  44.         except:
  45.             print "Couldn't find link\nLast comic's url : %s" % (self.comic_url)          
  46.             self.run = False
  47.  
  48.     def getHTML(self, url):
  49.         return urllib.urlopen(url).read()
  50.    
  51.     def find(self, arr, needle):
  52.         results = re.search("("+needle+".*)", arr)
  53.         if results:
  54.             return results.group(1)
  55.         else:
  56.             return None
  57.  
  58.     def download(self, url):
  59.         try:
  60.             os.system("wget "+url+"")
  61.             print "Downloaded : %s" % (url)
  62.         except:
  63.             print "Couldn't download!"
  64.  
  65. Downloader()
Add Comment
Please, Sign In to add comment