通过 python 和 wget 批量下载文件(在Linux/Ubuntu/Debian中测试)

首先创建一个文本文件d.txt, 一行一个链接。

你可以使用简单的 Python 脚本逐行读取文件 (d.txt) 中的链接,并使用 wget 下载文件:

复制代码
import subprocess

# File containing download links (replace with your file path)
file_path = 'd.txt'

# Function to download files using wget
def download_files(links_file):
    with open(links_file, 'r') as file:
        for line in file:
            # Remove leading and trailing whitespaces and newlines
            link = line.strip()
            
            # Run wget command to download the file
            subprocess.run(['wget', link])

# Call the function with the specified file path
download_files(file_path)
```

Make sure to replace `'d.txt'` with the actual path to your file containing download links. This script assumes that each line in the file corresponds to a download link.

Save this script with a `.py` extension (e.g., `download_script.py`) and run it using:

确保将"d.txt"替换为包含下载链接的文件的实际路径。 该脚本假定文件中的每一行都对应一个下载链接。

使用".py"扩展名保存此脚本(例如"download_script.py")并使用以下命令运行它:

复制代码
python download_script.py

该脚本将使用"wget"为文件中指定的每个链接顺序下载文件。

相关推荐
txzz88887 分钟前
CentOS-Stream-10 搭建NTP服务器(一)
linux·服务器·centos·ntp服务
站大爷IP21 分钟前
Python实现Excel数据自动化处理:从繁琐操作到智能流程的蜕变
python
BBB努力学习程序设计25 分钟前
Python 进阶知识点精讲:上下文管理器(Context Manager)的原理与实战
python·pycharm
清水白石00827 分钟前
《深入 super() 的世界:MRO 与 C3 线性化算法的全景解析与实战指南》
python
大厂技术总监下海28 分钟前
Python 开发者的“新引擎”:Rust 编写的解释器,性能与安全兼得
python·开源
冉佳驹1 小时前
Linux ——— 虚拟地址、页表、物理地址与 waitpid 和进程管理中的核心概念和技术
linux·waitpid·进程程序替换·exit·地址空间·非阻塞轮询·exec系列
Swizard1 小时前
别再硬编码配置了!5分钟带你用 PyYAML 让 Python 项目“活”起来
python
最后一个bug1 小时前
CPU的MMU中有TLB还需要TTW的快速查找~
linux·服务器·系统架构
love530love1 小时前
Windows 下 Z-Image-Turbo 专业版 Gradio 生成器实战:功能增强全记录
人工智能·windows·python·大模型·gradio·博客之星·z-image
人工干智能2 小时前
Chat Completions API中的三种role:“system“,“user“,“assistant“
python·llm