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

相关推荐
磁场转动100万匹1 小时前
PyTorch 手写数字识别实战:从数据加载到模型训练(零基础详解版)
人工智能·pytorch·python
2401_868534787 小时前
指令集-最常用 Linux 命令速查手册(整合版)
linux·网络协议
青 春 记 忆7 小时前
零基础入门python30:Flask个人账本从空目录运行与阶段验收
python·flask·后端开发
ltl7 小时前
小文件问题:文件数量如何放大元数据与 I/O 成本
linux
ltl7 小时前
网络延迟优化:Nagle、TCP_NODELAY 与中断亲和
linux
l1258657 小时前
# LangGraph Memory机制深度解析:短期记忆与长期记忆的工程实践
前端·人工智能·python·langchain·bootstrap
张文君8 小时前
ubuntu26.04从ext4改成mdadm的raid1+lvm启动
linux·运维·网络
xx~t8 小时前
嵌入式——进程与线程1
linux·c语言·学习·嵌入式·进程与线程
DevHub8 小时前
QEMU + Busybox 搭建嵌入式 Linux 开发环境:内核编译到启动,30 秒一个迭代
linux·运维·服务器