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

相关推荐
好家伙VCC1 分钟前
# ARCore+ Kotlin 实战:打造沉浸式增强现实交互应用在
java·python·kotlin·ar·交互
卖报的大地主2 分钟前
130万对像素级对齐:SOMA-1M如何打通遥感多模态数据的“最后一公里“
人工智能·python·计算机视觉
亚林瓜子3 分钟前
AWS Glue Python Shell任务中读取Athena数据库
数据库·python·shell·aws·glue·athena
zhangchaoxies4 分钟前
Golang怎么用K8s Secret管理密钥_Golang如何从K8s Secret安全读取密码和证书【操作】
jvm·数据库·python
2402_854808375 分钟前
JavaScript中模块化在游戏引擎开发中的资源调度作用
jvm·数据库·python
凤年徐5 分钟前
【Linux从入门到进阶】打包压缩、跨平台互传、内核版本、热键历史、关机与Shell原理一篇全搞定
linux·运维·服务器
生信研究猿6 分钟前
第2题-模型推理量化加速优化问题
python·算法
i建模7 分钟前
Linux 服务器上配置 XFCE 桌面以实现远程登录
linux·运维·服务器
看海的四叔7 分钟前
【Python】阿里云 DataWorks + ODPS + 钉钉联动实战:配合[特殊字符]全搞定
python·阿里云·api·odps·requests·openclaw
辰风沐阳1 小时前
nvm - node 版本管理工具【macOS/Linux】
linux·运维·macos