import urllib.request, os
#Check if folder exists, if not create folder
def check_folder_exists(folder_name):
if not os.path.isdir(folder_name):
os.makedirs(folder_name)
folder_name = str(/downloads/2017/)
check_folder_exists(folder_name)
urllib.request.urlretrieve(url, (folder_name +'foo.txt'))