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

相关推荐
论迹7 分钟前
【Git】-- Git安装 & 卸载(ubuntu)
git·ubuntu·elasticsearch
cnxy1881 小时前
Python爬虫进阶:反爬虫策略与Selenium自动化完整指南
爬虫·python·selenium
论迹1 小时前
【Git】-- Git基本操作
git·ubuntu
用户8356290780512 小时前
Python 实现 Excel 条件格式自动化
后端·python
相偎2 小时前
Ubuntu搭建svn服务器
服务器·ubuntu·svn
深蓝电商API2 小时前
Scrapy管道Pipeline深度解析:多方式数据持久化
爬虫·python·scrapy
噎住佩奇3 小时前
(Win11系统)搭建Python爬虫环境
爬虫·python
basketball6163 小时前
python 的对象序列化
开发语言·python
rgeshfgreh3 小时前
Python流程控制:从条件到循环实战
前端·数据库·python
luoluoal3 小时前
基于python大数据的电影市场预测分析(源码+文档)
python·mysql·django·毕业设计·源码