|
| 1 | +# File Downloader |
| 2 | + |
| 3 | +This script allows you to easily download files from a given URL and save them to a local directory. It utilizes the `requests` library to handle the HTTP requests and provide a convenient way to download files. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before running this script, ensure that you have the following installed: |
| 8 | + |
| 9 | +- Python 3.x |
| 10 | +- The `requests` library. You can install it by running the following command: |
| 11 | + |
| 12 | + ``` |
| 13 | + pip install requests |
| 14 | + ``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +1. Import the `requests` library: |
| 19 | + |
| 20 | + ```python |
| 21 | + import requests |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Define the `download_file` function, which takes three parameters: `url`, `save_path`, and `file_name`. This function downloads the file from the provided URL and saves it to the specified location. |
| 25 | + |
| 26 | + ```python |
| 27 | + def download_file(url, save_path, file_name): |
| 28 | + response = requests.get(url) |
| 29 | + file_path = save_path + "\\" + file_name |
| 30 | + with open(file_path, 'wb') as file: |
| 31 | + file.write(response.content) |
| 32 | + print("File downloaded successfully!") |
| 33 | + ``` |
| 34 | + |
| 35 | +3. Provide the necessary information: |
| 36 | + |
| 37 | + - Specify the URL of the file you want to download: |
| 38 | + |
| 39 | + ```python |
| 40 | + file_url = "https://files.ceenaija.com/wp-content/uploads/music/2022/09/Keane_-_Somewhere_Only_We_Know_CeeNaija.com_.mp3" |
| 41 | + ``` |
| 42 | + |
| 43 | + - Set the save path where you want to store the file. Replace `YOUR_SAVE_PATH` with the desired directory path: |
| 44 | + |
| 45 | + ```python |
| 46 | + save_path = r"YOUR_SAVE_PATH" |
| 47 | + ``` |
| 48 | + |
| 49 | + - Prompt the user to enter the desired file name: |
| 50 | + |
| 51 | + ```python |
| 52 | + file_name = input("Enter the file name: ") |
| 53 | + ``` |
| 54 | + |
| 55 | +4. Download the file by calling the `download_file` function with the provided parameters: |
| 56 | + |
| 57 | + ```python |
| 58 | + download_file(file_url, save_path, file_name) |
| 59 | + ``` |
| 60 | + |
| 61 | +The file will be downloaded and saved to the specified location. You can customize the script to fit your specific needs by modifying the URL, save path, and file name. |
0 commit comments