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

相关推荐
进击的明明7 小时前
当AI开始“边想边干”:深入聊聊ReAct,以及如何用Python手搓一个简单Agent
python·面试·agent
全栈弄潮儿8 小时前
Python实战第8期:函数
后端·python·编程语言
GeW8 小时前
新质生产力路线图Linux、数据库、国产化替代一次讲透
linux
卷无止境10 小时前
暗流与破局:AI时代的代码安全审查工具全景指南
后端·python
aningx10 小时前
cachyos 从 GRUB 切换到 rEFInd
linux
第404号工位12 小时前
40块钱二手瘦客户端,如何跑满家庭物联网中枢?(拒绝Docker爆盘实录)
linux·架构·node.js
卷无止境12 小时前
一人公司的全栈选型指南:让 AI Agent 写得快,也让生意跑得稳
后端·python
骑着蜗牛撵大象32713 小时前
Linux 进程间通信之管道:从 pipe() 的内核语义到 FIFO 落地排错
android·java·linux·系统编程·fifo·管道·进程间通信
..Dauntless..14 小时前
【Linux】一切皆文件和缓冲区
linux·运维·服务器
QMCY_jason14 小时前
x86 ubuntu2204 无gui 安装 openeuler 2203 aarch64版本
linux·运维·服务器