Created
October 15, 2012 19:05
-
-
Save kappa7194/3894439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import bs4 | |
import re | |
import urllib2 | |
import logging | |
class Resource(object): | |
url = None | |
request = None | |
content = None | |
def __init__(self, url, auto_get=True): | |
self.url = url | |
self.request = urllib2.Request(self.url) | |
if auto_get: | |
self.get() | |
def get(self): | |
self.content = urllib2.urlopen(self.request).read() | |
def save(self, destination_path): | |
if self.content is None: | |
self.get() | |
with open(destination_path, "wb") as output_file: | |
output_file.write(self.content) | |
class Chapter(object): | |
name = None | |
url = None | |
class Manga(Resource): | |
soup = None | |
chapters = [] | |
def __init__(self, url): | |
super(Manga, self).__init__(url) | |
self.soup = bs4.BeautifulSoup(self.content) | |
self.content = self.soup.prettify() | |
for snippet in self.soup.find_all("tr", class_=re.compile("row")): | |
chapter = Chapter() | |
chapter.name = snippet.find("td").string | |
chapter.url = snippet.find("a")["href"] | |
self.chapters.append(chapter) | |
logging.basicConfig(level=logging.DEBUG) | |
logging.debug("Fetching manga page.") | |
home = Manga("http://stoptazmo.com/manga-series/chokotto_sister/") | |
logging.debug("Manga page fetched.") | |
for chapter in home.chapters: | |
logging.debug("Fetching chapter %s" % chapter.name) | |
download = Resource(chapter.url, auto_get=False) | |
download.request.add_header("Referer", "http://stoptazmo.com/manga-series/chokotto_sister/") | |
logging.debug("Saving chapter %s" % chapter.name) | |
download.save("/Users/Albireo/Downloads/Chokotto Sister/" + chapter.name) | |
logging.debug("Chapter %s fetched." % chapter.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment