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

相关推荐
lightqjx7 小时前
VS Code连接Linux远端服务器的方法
linux·服务器·vs code
玫幽倩7 小时前
2026聚合獬豸杯决赛wp(手机取证)
python·电子取证·misc·取证·聚合·手机取证·獬豸杯
FlyWIHTSKY8 小时前
在智能体系统中,什么是多模态,举例详细说明
人工智能·python·langchain
琥珀色糖8 小时前
Linux GDB调试
linux·运维·服务器·gdb·调试
问天_观心8 小时前
虚拟环境WSL之Ubuntu的安装
人工智能·ubuntu
weixin_307779138 小时前
PHP 大文件上传:内存占用、超时与最佳实践
linux·服务器·开发语言·nginx·php
闲云野鹤在人间8 小时前
项目实战:LNMP-电商平台-ECshop
linux·运维·nginx·apache·lvs
吹什么轩9 小时前
linux网络:UDP套接字的业务实现:字典
linux·运维·udp
迷途之人不知返9 小时前
gcc编译器,以及源文件的翻译
linux