download

 

import requests def download_file(url, filename): """Downloads a file from the specified URL and saves it with the given filename. Args: url: The URL of the file to download. filename: The name of the file to save the downloaded content as. """ response = requests.get(url, stream=True) if response.status_code == 200: with open(filename, 'wb') as f: for chunk in response.iter_content(1024): f.write(chunk) print(f"File downloaded successfully: {filename}") else: print(f"Download failed with status code: {response.status_code}") # Example usage (replace with a valid image or video URL) image_url = "https://www.example.com/image.jpg" video_url = "https://www.example.com/video.mp4" download_file(image_url, "downloaded_image.jpg") download_file(video_url, "downloaded_video.mp4")

Comments

Popular Posts