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

相关推荐
打工仔折腾 AI7 分钟前
System Prompt 替代 Few-shot:用规则约束大模型输出的省钱实践
java·人工智能·python·spring·langchain·prompt·ai agent 实战
一号弯8 分钟前
Hyperv的LINUX虚拟机扩容
linux·运维·服务器
打工仔折腾 AI12 分钟前
从零写一个CAD 05:以鼠标为中心的滚轮缩放,招法能复用但顺序不能反
开发语言·后端·python·性能优化·计算机外设·swift·ai agent 实战
缘友一世17 分钟前
银河护卫队在steam(linux Proton GE-Proton10-34)上启动无窗口问题修复
linux·ubuntu·steam·proton
for_ever_love__25 分钟前
控制流——if、for、while 与可迭代对象
python·大模型开发·循环·控制流
for_ever_love__26 分钟前
PyTorch 张量与 autograd——自动求导怎么工作
pytorch·python·深度学习·自动求导
wunaiqiezixin26 分钟前
MIT 6.S081 util 实验篇(lab1):primes (moderate/hard)
linux·unix·os·xv6·mit6.s081
小小张说故事39 分钟前
Python 里 `is` 和 `==` 到底差在哪?5 个让你怀疑人生的案例 + 对照表
python
硅基手札1 小时前
【Linux 内核专栏 13】快IO层
linux·服务器·嵌入式硬件
嵌入式分享1 小时前
嵌入式分享#63:RK3588 怎么选?全系列选型指南
linux