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

相关推荐
databook4 分钟前
异常值检测与处理方法总结
python·数据挖掘·数据分析
千里码aicood5 分钟前
面向智能助理的多轮医疗对话生成系统开发
python
MC皮蛋侠客8 分钟前
OPC UA 系列(一):标准全景与 Python 最小闭环——让第一条设备数据流动起来
开发语言·python·opcua
fangjianj9 分钟前
windows环境反弹shell
linux·windows·web安全
用户37215742613510 分钟前
使用 Python 提取 Word 文档中的表格数据
python
有味道的男人13 分钟前
得物详情 API|支持实时价格、成色、鉴别服务数据
windows·python·api
小溪学编程17 分钟前
Java BufferedReader 详解:从基础用法到性能优化
java·python·性能优化
明月不会写代码20 分钟前
Ubuntu 下 Kitty 终端配置记录
linux·ubuntu
2601_9623004732 分钟前
基于Python与Tkinter的ADB Monkey自动化测试脚本开发
python·adb·tkinter·android测试·gui自动化
weipt34 分钟前
利用wsl给windows电脑上安装一个ubuntu
linux·运维·ubuntu