Skip to content

Instantly share code, notes, and snippets.

@wkentaro
Created November 13, 2014 23:46
Show Gist options
  • Save wkentaro/4a2d4c2378d1834d8f6a to your computer and use it in GitHub Desktop.
Save wkentaro/4a2d4c2378d1834d8f6a to your computer and use it in GitHub Desktop.
Get images from url.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# main.py
import sys
from PIL import Image
import requests
from io import BytesIO
f = open('image_urls.txt', 'rb')
rows = f.readlines()
for i, url in enumerate(rows):
try:
response = requests.get(url)
img = Image.open(BytesIO(response.content))
except IOError:
continue
img.save('imgs/train{}.png'.format(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment