Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created March 29, 2019 05:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save msurguy/b2eb5a942bf02865666786bcef7ff7fc to your computer and use it in GitHub Desktop.
Pythoin File downloader
import csv, sys
#import requests
import urllib.request
#from urllib.request import urlopen
import os
filename = 'test.csv'
with open(filename, mode='r', encoding='utf-8-sig') as f:
reader = csv.reader(f)
try:
for row in reader:
if 'http' in row[0]:
print (row)
rev = row[0][::-1]
i = rev.index('/')
tmp = rev[0:i]
print (tmp[::-1])
urllib.request.urlretrieve(row[0].strip(), "./"+tmp[::-1])
except csv.Error as e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment