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

相关推荐
摇滚侠6 分钟前
《On Java 中文版 基础卷》阅读笔记 复用 13
java·笔记·python
用户2986985301412 分钟前
Python 将 Word 文档转换为 XML 的实践要点
后端·python·api
薛之谦_15 分钟前
用 Java 实现阿里云式 IAM 子用户管理:架构设计与表结构详解
java·python·阿里云
2601_9520477916 分钟前
金蝶云星空销售订单附件查询接口权威教程(BOS_Attachment)
python·机器人·钉钉
bu_shuo18 分钟前
删除Windows资源管理器左侧【此电脑】的Linux企鹅图标
linux·windows
步行cgn19 分钟前
Spring MVC 删除功能:用隐藏表单模拟 DELETE 请求的完整解析
linux·运维·服务器
神仙别闹19 分钟前
基于Python Yolo实现绝缘子目标检测程序
python·yolo·目标检测
超级架构师36 分钟前
让 COBOL 长出 AI 大脑:原生 Agent 核心框架 praxo-core 深度剖析
c语言·开发语言·c++·人工智能·python·架构·ai编程
甜到心里的蛋糕43 分钟前
抖音评论自动回复机器人部署实践:无头 Chrome + DeepSeek + NapCat(2C2G 云主机)
java·jvm·chrome·python·抖音·deepseek
宁波阿成1 小时前
CentOS 7 环境下 Tomcat 8.5 升级至 9.0.123 操作总结
linux·centos·tomcat