zaporn.net
Python script for downloading image galleries

Python script for downloading image galleries

This is a simple Python script that will download all images from a specified image gallery into a folder with the gallery id (e.g., 252306). Requires Python 2.7 and the BeautifulSoup package. Indenting spaces don't seem to show up here, so you'll need to strip out the # before each line.

#from bs4 import BeautifulSoup
#import urllib
#import re
#import os
#
## Set this to the URL of the image gallery
#url = "http://xhamster.com/photos/gallery/252306/looking_up.html"
#
#def getBase(link):
# imgpage = BeautifulSoup(urllib.urlopen(link['href']))
# imgs = imgpage.find_all(src=re.compile("_1000"))
# if len(imgs) > 0:
## return imgs[0]['src'].rsplit("/",1)[-2]
#
#
#page = BeautifulSoup(urllib.urlopen(url))
#links = page.find_all('a')
#
#gallery_id = url.split("/")[-2]
#if not os.path.exists(gallery_id):
# os.makedirs(gallery_id)
#
## Get base URL for images
#base = ""
#for link in links:
# if gallery_id in link['href']:
## base = getBase(link)
## break
#
#print base
#for link in links:
# if gallery_id in link['href']:
## photo_id = link['href'].split(".html")[0][-3:]
## print photo_id
## if (photo_id.isdigit()):
### urllib.urlretrieve(base + "/" + photo_id + "_1000.jpg", gallery_id + "/" + photo_id + ".jpg")
Published by massivenutsack
8 years ago
Comments
Please or to post comments