Created
July 6, 2019 00:05
-
-
Save Santiago-j-s/a7de860da41121841517bda0317a52b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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