通过 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"为文件中指定的每个链接顺序下载文件。

相关推荐
万年咸鱼14 分钟前
解决C语言的内存释放机制
java·c语言·python
破芽30 分钟前
python知识点整理02
开发语言·python
一木 之林30 分钟前
DeepSeek Agent 开发(三)
java·大数据·linux
打工仔折腾 AI1 小时前
Docker镜像分层与卷挂载到底怎么工作:一次文件系统层面的实测分析
运维·人工智能·后端·python·docker·容器·性能优化
老歌老听老掉牙1 小时前
麻花钻锥面后刀面数学模型的完整推导与数值求解
python·钻头·后刀面
墨染天姬1 小时前
【人工智能训练师】python语法二
开发语言·人工智能·python
大猫会长1 小时前
调用codebuddy集成的supabase授权白屏解决方法
linux·运维·服务器
羔羊++2 小时前
29_实验二十八_buildroot配置与编译
linux
LoneEon2 小时前
CentOS7 部署 Nacos3.x 集群实战:从注册中心到 AI 管理中心
linux·人工智能·nacos
传人2 小时前
为什么 Xshell 中可以通过java -version查询到java 版本号码,Electerm 却查不到?
java·linux·服务器