Skip to content

Instantly share code, notes, and snippets.

@craigmbooth
Created April 2, 2017 15:20
Show Gist options
  • Select an option

  • Save craigmbooth/d70924d4f1875c1a319b5f40e2851cd7 to your computer and use it in GitHub Desktop.

Select an option

Save craigmbooth/d70924d4f1875c1a319b5f40e2851cd7 to your computer and use it in GitHub Desktop.
This script downloads all of the images from the billboard gallery on the website of Robert Montgomery.
"""I wanted a screensaver of Robert Montgomery poems. This script pulls
them from the gallery on his website
"""
import os
import sys
from bs4 import BeautifulSoup
import requests
if __name__ == "__main__":
res = requests.get("http://www.robertmontgomery.org/new-gallery/")
if not res.ok:
sys.exit("Failed to fetch website")
# The page has a div with class=slide for each image, which contains
# an img tag for the image itself
soup = BeautifulSoup(res.text, 'html.parser')
for slide in soup.findAll('div', attrs={'class':'slide'}):
img = slide.find('img')
if img is None:
continue
data = requests.get(img["src"])
with open(os.path.join("images", img["src"].split("/")[-1]), "wb") as f:
for chunk in data:
f.write(chunk)
print "Saved: {}".format(img["src"].split("/")[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment