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

相关推荐
nenchoumi31194 分钟前
AirSim/Cosys-AirSim 游戏开发(一)XBox 手柄 Windows + python 连接与读取
windows·python·xbox
GoodStudyAndDayDayUp5 分钟前
初入 python Django 框架总结
数据库·python·django
星辰大海的精灵13 分钟前
基于Dify+MCP实现通过微信发送天气信息给好友
人工智能·后端·python
精灵vector18 分钟前
Agent短期记忆的几种持久化存储方式
人工智能·python
子正23 分钟前
一键编译包含多个独立模块和应用的工程(linux cmake)
linux·运维·cmake
小阳睡不醒25 分钟前
小白成长之路-Linux Shell脚本练习
linux·运维·服务器
北京_宏哥33 分钟前
🔥Python零基础从入门到精通详细教程4-数据类型的转换- 上篇
前端·python·面试
乾巫宇宙国监察特使43 分钟前
Python的设计模式
python·测试
Hockor1 小时前
写给前端的 Python 教程四(列表/元组)
前端·后端·python
dessler1 小时前
代理服务器-LVS的DR模式
linux·运维·云计算