Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 1
Message 1 of 2

Need help with basic python URL download func

import os.path
import urllib.request

filepath = input('please input the url file path: ')
links = open ('urls.txt', 'r')
newpath = input('Where would you like to store the file? ')
for link in links:

# Get one line of text (e.g. C:\user\path\directory),
# then get the filename from the end of the URL
link = link.strip ()
filename = link.rsplit ('/', 1)[-1]

# Does this file exist in this folder? If not, download it
if not (os.path.isfile (filename)):
print ('Downloading: ' + newpath + filename)
try:
urllib.request.urlretrieve (link, newpath + filename)
newfilename = input (" Type in the new name for the file: ")
print ("File size was", os.path.getsize (filename))
except Exception as inst:
print (inst)
print (' Encountered unknown error. Continuing.')

# File exists; don't download
else:
print ("This file exists already.")

# End of program
print ("Finished downloading.")





I have been trying to wrack my brain around this but to say my brain is 404 would be an understatement.

if anyone could help me fix my problems or assist i would greatly appreciate it.

 

1 Reply
Highlighted
Commander Lvl 2
Message 2 of 2

Re: Need help with basic python URL download func

If you'd tell us what the problem(s) are, and/or where in the program it is "going wrong", then we might be able to assist ...

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!