Skip to content

Instantly share code, notes, and snippets.

@melpomene
Created January 19, 2012 00:37
Show Gist options
  • Save melpomene/1636776 to your computer and use it in GitHub Desktop.
Save melpomene/1636776 to your computer and use it in GitHub Desktop.
Script to download all Amigara episodes. [ugly hack]
import urllib
import requests
from BeautifulSoup import BeautifulSoup
""" CHANGE PATH TO DIRECTORY IN WHICH TO SAVE FILES AND ALL IS WELL"""
PATH = "path/to/file"
url = "http://brasscockroach.com/h4ll0w33n2007/manga/Amigara-Full/Amigara-0.html"
img_url = "http://brasscockroach.com/h4ll0w33n2007/manga/Amigara-Full/"
r = requests.get(url)
count = 0
old = "t"
last_url = ""
new_url = url
while r.status_code == 200:
content = r.content
soup = BeautifulSoup(content)
img = soup.find('img')
img_path = img_url + str(urllib.quote(str(img['src'])))
f = open(PATH+ str(count) + ".png", "w")
i = requests.get(img_path)
f.write(i.content)
n = soup.findAll('a')
new_url = img_url + str(n[1]['href'])
if new_url == old:
print "All img downloaded"
exit()
print new_url
r = requests.get(new_url)
old = last_url
last_url = new_url
count+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment