Skip to content

Instantly share code, notes, and snippets.

@kevin-chau
Last active October 13, 2023 04:03
Show Gist options
  • Save kevin-chau/0d106f863f59bdc50d764a8ad6edfec8 to your computer and use it in GitHub Desktop.
Save kevin-chau/0d106f863f59bdc50d764a8ad6edfec8 to your computer and use it in GitHub Desktop.
US Forest Service Research Image Library Scraper
import requests
output_dir = "/Volumes/KCHAU'S T5/US Forest Service Research Image Library/"
url_base = 'https://www.fs.usda.gov/rds/imagedb/images/'
# 19677 = total number of images in data base
file_number = 19677
while file_number > 0:
filename = str(file_number) + '.jpg'
r = requests.get(url_base + filename)
if r.status_code != 404:
img_data = r.content
with open(output_dir+filename, 'wb') as handler:
handler.write(img_data)
file_number -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment