从 URL 列表批量下载 Google Drive 中的文件

从 URL 列表批量下载 Google Drive 中的文件

我有 100 个 URL 列表,这些 URL 链接到我想要下载的 Google Drive 上的文件。每个 URL 都像这样:

https://drive.google.com/file/d/0B8asdfasdfasd4YXc/view?usp=sharing

我如何批量下载它们?理想情况下,我会将网址放在一个文本文件中,然后某些程序会下载它们。它们是视频

好的,我可以将 URL 更改为如下形式:

https://drive.google.com/uc?export=download&id=[TheFileID]

但我仍然需要点击“仍然下载”按钮

答案1

我找到了一个可以打开多个 URL 的扩展程序。我将下载设置更改为不确认,然后我就可以以以下格式粘贴 URL 列表https://drive.google.com/uc?export=download&id=[TheFileID]让它们全部下载。Chrome
扩展名为“打开多个 URL” https://chrome.google.com/webstore/detail/open-multiple-urls/oifijhaokejakekmnjmphonojcfkpbbh/related?hl=en

答案2

步骤

  1. 使用以下命令安装 gdown pip install gdown- 该命令对我来说在标准 Windows 11 PowerShell 中有效。(请确保已安装 Python 和 Pip 来执行此命令)

  2. 创建一个包含您的链接的 .txt 文件,按以下方式列出:

https://drive.google.com/file/d/someID/view
https://drive.google.com/file/d/someotherID/view
and so on - Don't put anything that is not a link here
  1. 编辑以下脚本顶部的变量以满足您的需要。

  2. 运行

  3. 如果一切顺利,你会在你指定的目录中找到你的文件

剧本

from os import chdir
from typing import List
from gdown import download
from requests.exceptions import MissingSchema

my_links_file_path: str = r'C:\Users\Jakub\Desktop\a\download_links.txt'  # EDIT THIS!
my_output_directory_path: str = r'C:\Users\Jakub\Desktop\a'  # EDIT THIS!


def google_drive_bulk_download(links_file_path: str, output_directory_path: str):
    try:
        file = open(links_file_path, 'r')
    except FileNotFoundError:
        print(f"\n!!! The File '{links_file_path}' is Invalid!\n")
        return

    try:
        chdir(my_output_directory_path)
    except FileNotFoundError:
        print(f"\n!!! The File '{output_directory_path}' is Invalid!\n")
        return

    file_lines: List[str] = [stripped_line for stripped_line in
                             [line.strip() for line in file.readlines()]
                             if stripped_line]
    file_lines_count: int = len(file_lines)

    print('\n\n==> Started Downloading!\n')

    for i, url_raw in enumerate(file_lines, start=1):
        download_url: str = url_raw.strip()

        print(f'\n-> Downloading... [{i}/{file_lines_count}]')

        try:
            download(url=download_url, quiet=False, fuzzy=True)
        except MissingSchema:
            print(f"!!! The URL '{download_url}' is Invalid!")

        print('Finished!')

    print('\n\n==> Finished Downloading!')


google_drive_bulk_download(my_links_file_path, my_output_directory_path)

笔记

  • 此方法对我有用。在 Windows 11、Python 3.10 和 Python 3.11 上。

  • 该脚本可能适用于其他格式的 Google Drive 链接,也可能不适用。

  • 如果下载失败,您可能需要尝试使用 VPN - 我不得不这么做。

  • 有许多浏览器扩展程序可以帮助您列出当前打开的浏览器选项卡的 URL。无需手动操作。

相关内容