I have a very large Python script that I am using pyinstaller with to create an exe. I need to download an XML file but would like to keep the exe as small as possible as it is already getting quite large.
Is there a method within Python to get a file from a URL? I was not able to find anything without an external library
You can use urllib.urlretrieve() that saves the opened page to the specified path.
Alternatively you can open the url with urllib.urlopen() and then write the read file in the binary mode:
import urllib
urllib.urlretrieve(url, destination_path) # First and short way
with open(destination_path, 'wb') as f: # Equivalent to the first, but longer
f.write(urllib.urlopen(url).read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With