通过 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 分钟前
运费分摊的二开实现:BigDecimal 精确分摊 + 尾差补齐 + 暂估调整
开发语言·python
Ryan-Zhong1 小时前
一次接入 16 个平台:视频链接元数据解析 API 的 Python 实战与踩坑记录
开发语言·python·dreamweaver
handsome_sai1 小时前
《Linux 小白查看系统与软件商店指南》
linux·运维·服务器
Rabitebla1 小时前
【Linux】 文件系统(五):挂载与软硬链接,多个文件系统怎样组成统一目录树
linux·运维·服务器·c++·笔记·学习·算法
皓月盈江1 小时前
云服务器上部署Hexo静态博客
linux·服务器·hexo·个人博客·云服务器·个人网站·静态博客
qeen873 小时前
【Linux】线程的基本认识及与进程的关系、对比
linux·运维
aihuge20263 小时前
RAG 检索要不要加缓存:同查询二次命中省一次计算,语料一变就得失效
python·大模型·rag
向科→向总工→空间动态计系统4 小时前
动态零轴融合三铁律
大数据·开发语言·人工智能·python·机器人
疯华整猫4 小时前
一条 kill -9 杀不掉的进程:AI 时代,程序员为什么必须精通 Linux
linux
Cosolar4 小时前
Agent Harness 架构演进与核心设计原则:基于 Pi、OpenCode、Hermes、OpenClaw 的对比研究
python·llm·agent