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

相关推荐
SDAU20051 分钟前
ESP32C3在Arduino下的MQTT操作
linux·服务器·前端
梁正雄3 分钟前
linux服务-RabbitMQ 原理与安装
linux·rabbitmq·ruby
HIT_Weston3 分钟前
59、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(三)
前端·ubuntu·gitlab
骇客野人5 分钟前
Java @Mapper 使用注解的方式注入SQL
linux·服务器·windows
我送炭你添花6 分钟前
我送炭你献花:Pelco KBD300A 模拟器项目总览
python·功能测试·pyqt·运维开发
bank_dreamer6 分钟前
【ubuntu】vim作为默认编辑器
ubuntu·编辑器·vim
青铜弟弟8 分钟前
R语言与python升级包的问题
开发语言·python·r语言
CappuccinoRose9 分钟前
Docker配置过程完整梳理
后端·python·docker·容器·环境配置
Michelle802311 分钟前
24大数据 15-2 线性查找和选择排序
python
MUTA️12 分钟前
使用flask将服务器端的视频通过网页在本地查看
后端·python·flask