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

相关推荐
2401_832402752 分钟前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python
天天进步20153 分钟前
Python全栈项目--基于机器学习的垃圾邮件过滤系统
python
YiWait4 分钟前
机器学习导论习题解答
人工智能·python·算法
showker4 分钟前
Mac mini-macOS Tahoe 26.1-安装ftp服务-用户名密码都对,就是提示530 login incorrect
linux·服务器·数据库
m0_706653235 分钟前
自动化与脚本
jvm·数据库·python
XerCis6 分钟前
Python读取硬盘信息pySMART——调用smartctl
开发语言·python·硬件架构
流㶡6 分钟前
scikit-learn之KNN算法实战鸢尾花分类
python·算法·scikit-learn·knn
未来之窗软件服务7 分钟前
服务器运维(二十八)阿里云清理服务器瘦身降低漏洞风险—东方仙盟
linux·运维·服务器·仙盟创梦ide·东方仙盟
weixin_4465042212 分钟前
Akshare:一个实用的免费金融数据Python库
开发语言·python·金融
晨非辰2 小时前
Linux权限管理速成:umask掩码/file透视/粘滞位防护15分钟精通,掌握权限减法与安全协作模型
linux·运维·服务器·c++·人工智能·后端