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

相关推荐
MyFreeIT4 分钟前
Python Windows Manual
开发语言·python
骑着蜗牛撵大象3276 分钟前
手写一个 HTTP 服务器:从 socket 到 epoll,Linux 上到底怎么把请求变成响应
linux·服务器·网络·http·epoll·socket编程·并发模型
程序员初一8 分钟前
我在 1C1G 的服务器上装了个桌面环境,然后用 VNC 连它,然后我后悔了
linux·ssh
wusam11 分钟前
基于HCL的python脚本编程(2)
网络·python·智能路由器
神仙别闹20 分钟前
基于Python+MySQL实现(Web)个人博客系统
python·mysql·php
二十七日秋22 分钟前
算法刷题笔记「Day 1|四道 OJ 入门题里的深坑」
c语言·汇编·数据结构·c++·笔记·python·算法
星恒随风36 分钟前
Linux Socket TCP编程(二):逐文件重构多进程、多线程与线程池服务器,深入fork、pthread_create、popen和std::bind
linux·服务器·笔记·学习·tcp/ip
晚风叙码36 分钟前
Linux 进程概念(下):程序地址空间与虚拟内存
linux·服务器·算法
小咕聊编程1 小时前
基于Django的个人摄影博客网站设计与开发
后端·python·django
无足鸟ICT1 小时前
【RHCA+】影响Linux系统性能的因素
linux·运维·服务器