Skip to content

Instantly share code, notes, and snippets.

@Santiago-j-s
Created July 6, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Santiago-j-s/a7de860da41121841517bda0317a52b6 to your computer and use it in GitHub Desktop.
Save Santiago-j-s/a7de860da41121841517bda0317a52b6 to your computer and use it in GitHub Desktop.
import requests
from requests.exceptions import ConnectionError
with open('gi.csv', 'r') as f:
lineas = f.readlines()
urls = enumerate([linea.split(',')[0] for linea in lineas][1::])
session = requests.Session()
for index, url in urls:
print(url)
try:
r = session.get(url, stream=True)
except ConnectionError:
with open('errores.txt', 'a') as f:
print(f'No se pudo descargar {url}', file=f, end='\n')
continue
with open(f'imgs/{index}.jpg', 'xb') as f:
for chunk in r.iter_content(chunk_size=512*1024):
f.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment