小工具知识网

当前位置: 首页 > 行业知识 > 通过 python 和 wget 批量下载文件(在Linux/Ubuntu/Debian中测试)

行业知识

通过 python 和 wget 批量下载文件(在Linux/Ubuntu/Debian中测试)

2026-11-08 20:02:52 来源:互联网转载

首先创建一个���本文件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 wgetdef 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 pathdownload_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”为文件中指定的每个链接顺序下载文件。

上一篇:流浪方舟线上服务器怎么选?

下一篇:linux服务器怎么虚拟网卡?