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

相关推荐
haosend7 分钟前
极简小白Python教程-实现能基本看懂和简单编写代码
python·路由器·交换机·网络自动化
白云偷星子11 分钟前
RHCSA笔记7
linux·笔记
码农小韩16 分钟前
AIAgent应用开发——大模型理论基础与应用(六)
人工智能·python·提示词工程·aiagent·deepseek
tryCbest21 分钟前
Linux常用命令V2026
linux·运维
一株菌子25 分钟前
10.12 总结
开发语言·python
敏编程34 分钟前
一天一个Python库:pyjwt - 安全地编码和解码JWT
python
长安牧笛1 小时前
让车学会耍赖式安全停车,危险时优先靠边停车,不是硬刹,颠覆紧急制动逻辑,输出平稳停车。
python·编程语言
Loo国昌1 小时前
【AI应用开发实战】05_GraphRAG:知识图谱增强检索实战
人工智能·后端·python·语言模型·自然语言处理·金融·知识图谱
一个处女座的程序猿O(∩_∩)O1 小时前
Python面向对象的封装特性详解
开发语言·python
zhaoyin19941 小时前
python基础
开发语言·python