Louis I. answered 07/14/19
Computer Science Instructor/Tutor: Real World and Academia Experienced
Like most general purpose tasks in Python, this is very straightforward.
Research the urllib.request module.
See example code and script output below:
### START OF SCRIPT
import urllib.request
## down URL --> File Target
def download(url, file):
print("starting download: %s ==> %s" % (url, file))
urllib.request.urlretrieve(url, file) ### this is the key line of code ...
## return number of bytes in a names file ...
def sizeof(file):
fd = open(file, 'rb')
return len(fd.read())
source = "http://louisiacona.com/LouisIaconaResume.pdf"
target = "C:\\tmp\\resume.pdf"
download(source, target)
## show that we actually downloaded something
print("sizeof: %s = %d" % (target, sizeof(target) ) )
### END OF SCRIPT
## execution output
$ python download.py
starting download: http://louisiacona.com/LouisIaconaResume.pdf ==> C:\tmp\resume.pdf
sizeof: C:\tmp\resume.pdf = 94009
PS - this was tested using Python 3