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

相关推荐
城南观北18 分钟前
Ubuntu 解决 apt 锁占用 + 安装 net-tools + 搭建 SSH 远程连接(保姆级实操)
linux·ubuntu·ssh
s_w.h31 分钟前
【 linux 】文件管理与重定向
linux·运维·服务器
Cloud_Shy61837 分钟前
Linux 系统定时任务 Cron(d) 服务应用实践(二:生产环境下的用户定时任务)
linux·运维·服务器·centos·云计算
STDD44 分钟前
strace 和 perf:Linux 进程调试和性能分析深度指南
linux·运维·php
小江的记录本44 分钟前
【JVM虚拟机】垃圾回收GC:垃圾判定算法:引用计数法、可达性分析算法(附《思维导图》+《面试高频考点清单》)
java·jvm·后端·python·算法·spring·面试
Rain5091 小时前
05. mini-cc 工具系统:让 AI 拥有动手能力
linux·前端·人工智能·ubuntu·typescript·ai编程
清水白石0081 小时前
构建企业级 Python 服务:配置、日志、指标与追踪的稳健之道
开发语言·python·elasticsearch
都在酒里1 小时前
Linux字符设备驱动开发(五):PWM调光——实现LED亮度控制与呼吸灯效果
linux·运维·驱动开发
Hani_971 小时前
Code Coverage系列(三)gcov 是什么?做什么?两个参数?检测原理?gcno文件内容?gcda文件内容?
linux·代码覆盖率
happymaker06261 小时前
SpringBoot使用Thymeleaf模板引擎,前端的基本语法
开发语言·python