import requests def download_file(url, filename): response = requests.get(url, stream=True) with open(filename, 'wb') as f: for chunk in response.iter_content(chunk_size=1024): if chunk: f.write(chunk) print(f"文件已下载: {filename}") # 堆代码 duidaima.com # 示例用法 download_file("https://example.com/file.zip", "file.zip")此脚本可以自动下载指定URL的文件并保存到本地,适合批量文件下载或自动化备份任务。