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

相关推荐
lengjingzju17 分钟前
编译与调试完全指南—第10章 网络分析工具
linux
小陈的进阶之路35 分钟前
Claude Code辅助测试:导入篇skills
python·自动化
ltl1 小时前
新硬件对存储的影响:ZNS、CXL 与计算存储
linux
RisunJan1 小时前
Linux命令-xauth(X11 认证授权管理)
linux·服务器·microsoft
whcyhhh2 小时前
头歌实践教学平台:大数据存储2023(六)
大数据·数据库·python
for_ever_love__2 小时前
python基础语法学习: 闭包
开发语言·python·学习·闭包
ly76892 小时前
Python 全面入门:从核心语法到工程实践
开发语言·python
Niuguangshuo4 小时前
DeepFilterNet 3:端侧实时全带降噪的开源标杆
python
第一程序员4 小时前
AI 辅助编程的 7 个误区:把模型当高级搜索引擎是对它的最大浪费
python·rust·github
fb_123455 小时前
Linux三剑客超全精讲(grep+sed+awk)零基础入门|正则+实战面试题
linux·运维·服务器