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

相关推荐
Stack Overflow?Tan901 分钟前
标注软件labelImg在linux下鼠标滚轮闪退解决办法
linux·labelimg
李彦亮老师(本人)3 分钟前
Rocky Linux 9.x 新特性详解
linux·运维·服务器·centos·rocky linux
NiKick5 分钟前
在Linux系统上使用nmcli命令配置各种网络(有线、无线、vlan、vxlan、路由、网桥等)
linux·服务器·网络
胡耀超32 分钟前
Token的八副面孔:为什么“词元“不需要更好的翻译,而需要更多的读者
大数据·人工智能·python·agent·token·代币·词元
第一程序员2 小时前
Python与前端集成:构建全栈应用
python·github
程序员小远2 小时前
Jmeter基础:Jmeter聚合报告详解
自动化测试·软件测试·python·测试工具·jmeter·测试用例·压力测试
凌波粒2 小时前
D2L学习笔记:安装、张量与数据处理
笔记·python·学习·pandas
coderlin_2 小时前
从0开始构建Claude Code
python·ai编程
副露のmagic3 小时前
字符串章节 leetcode 思路&实现
windows·python·leetcode
扛枪的书生3 小时前
包管理器用法速查
linux