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

相关推荐
zzb15806 分钟前
Agent记忆与检索
java·人工智能·python·学习·ai
wangjialelele8 分钟前
一文读懂 Redis 持久化与事务
linux·数据库·redis·bootstrap
Linux蓝魔12 分钟前
麒麟官方yum源配置V10SP2-V10SP3-V10SP3-2403
大数据·linux·运维
helloliyh12 分钟前
linux 删除指定日期目录(包括目录下文件)
linux·运维·服务器
wzl2026121315 分钟前
从0到1搭建私域数据中台——公域引流的数据采集与分析
python·自动化·企业微信
半个俗人24 分钟前
06.Linux用户权限相关命令
linux·运维·服务器
小宇的天下25 分钟前
Calibre LVS Circuit Comparison(1)
linux·数据库·lvs
涛声依旧3931626 分钟前
构建部署kubernetes所需主机
linux·运维·云原生·容器·kubernetes
源码之家27 分钟前
大数据毕业设计汽车推荐系统 Django框架 可视化 协同过滤算法 数据分析 大数据 机器学习(建议收藏)✅
大数据·python·算法·django·汽车·课程设计·美食
HealthScience28 分钟前
COM Surrogate的dllhost.exe高占用(磁盘)解决
python