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

相关推荐
栈溢出了4 分钟前
VS Code Python 自动导包失效排查笔记
开发语言·笔记·python
DanCheng-studio5 分钟前
毕业设计项目 基于深度学习的抽烟行为检测算法实现(源码分享)
python·毕业设计·毕设
MicrosoftCloud7 分钟前
用户权限 02|/etc/passwd、/etc/shadow、/etc/group:三个文件讲透 Linux 用户体系
linux·运维·ubuntu·用户管理·权限·useradd
崽崽..13 分钟前
【Linux】ping命令刨析
linux·运维·服务器·网络
Wx-bishekaifayuan18 分钟前
springboot陨石鉴收系统96265-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·python·spring·课程设计
沫璃染墨31 分钟前
《从零入门Linux系统篇(五十六):线程篇·九——生产者消费者模型:从条件变量到BlockingQueue实现》
linux·服务器·c++·驱动开发·设计模式·架构·系统架构
张小姐的猫34 分钟前
【Linux】网络编程 —— 五种IO模型
linux·运维·服务器·网络·c++·人工智能·php
程序员-Benothing35 分钟前
Shell脚本调试与最佳实践:set -eux、shellcheck实战
linux·运维·服务器
本地化文档37 分钟前
pygmt-docs-l10n
python·github·gitcode·sphinx·pygmt·gmt·crowdin
Web3&Basketball37 分钟前
用 SGLang 决策端点做毫秒级 Agent 路由
python·大模型·agent·强化学习·多模态·推理