This is how I'm downloading:
webbrowser.open(download_url)
So I've got the URL and I'm just opening it with the webbrowser
module. This downloads whatever is on the other side of that URL to the default download location of my default browser.
How can I change this location to something I specify in my program? I feel like this should have a simple solution but I can't find anything about it on the web. I tried os.chdir()
and that had no effect.
When downloading a file, Wget stores it in the current directory by default. You can change that by using the -P option to specify the name of the directory where you want to save the file. Download the jQuery file you downloaded previously, but this time save it in the Downloads subdirectory.
Create cURL session. Declare a variable and store the directory name where the downloaded file will save. Use the basename() function to return the file basename if the file path is provided as a parameter. Save the file to the given location.
One of the simplest way to download files in Python is via wget module, which doesn't require you to open the destination file. The download method of the wget module downloads files in just one line. The method accepts two parameters: the URL path of the file to download and local path where the file is to be stored.
Use urllib.urlretrieve
(urllib.request.urlretrieve
in Python 3.x):
import urllib
urllib.urlretrieve('http://example.com/file.ext', '/path/to/directory/filename.ext')
NOTE the second argument should be file path, not directory path.
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