使用 Python 下载共享的 Google Drive 文件夹

时间:2023-03-04
本文介绍了使用 Python 下载共享的 Google Drive 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌驱动器上有一个只有 .jpg 图像的文件夹,我想使用该文件夹的共享链接将文件夹中的所有图像下载到我的计算机.

I have a folder on the google drive with just .jpg images and I want to download all of the images in the folder to my computer using the folder's shared link.

到目前为止,我发现唯一有效的是下面的代码,但我只能让它适用于特定的共享文件,而不是整个文件夹.

So far, the only thing that I have found that works is the code below but I can only get it to work for specific shared files and not an entire folder.

from google_drive_downloader import GoogleDriveDownloader as gdd

gdd.download_file_from_google_drive(file_id='1viW3guJTZuEFcx1-ivCL2aypDNLckEMh',
                                    dest_path='./data/mnist.zip',
                                    unzip=True)

有没有办法修改它以使用 google 文件夹,或者是否有其他方法可以下载 google drive 文件夹?

Is there a way to modify this to work with google folders or is there another way to download google drive folders?

推荐答案

你可以使用gdrive 工具.基本上它是一个从命令行访问谷歌驱动器帐户的工具.按照这个 Linux 机器的示例进行设置:

You can use the gdrive tool. Basically it is a tool to access a google drive account from command-line. Follow this example for a Linux machine to set this up:

  1. 首先下载gdrive的执行文件这里.
  2. 解压得到可执行文件gdrive.现在通过执行命令更改文件的权限chmod +x gdrive.
  3. 运行./gdrive about,你会得到一个URL,要求你输入验证码.按照提示复制链接并转到您的浏览器上的 URL,然后登录您的 Google Drive 帐户并授予权限.最后你会得到一些验证码.复制它.
  4. 返回之前的终端,粘贴刚刚复制的验证码.然后验证你的信息在那里.现在您已成功将您的机器链接到您的 Google Drive帐户.
  1. At first download the execution file of gdrive here.
  2. Decompress it and get the executable file gdrive. Now change the permissions of the file by executing the command chmod +x gdrive.
  3. Run ./gdrive about and you will get a URL asking you to enter for a verification code. As instructed in the prompt copy the link and go to the URL on your browser, then log into your Google Drive account and grant permission. You will get some verification code at last. Copy it.
  4. Go back to your previous terminal and paste the verification code you just copied. Then verify your information there. Now you successfully link your machine to your Google Drive account.

现在完成上述过程后,您可以使用下面提到的命令浏览驱动器上的文件.

Now once done with the above process you can navigate the files on your drive using the commands mentioned below.

./gdrive list # List all files' information in your account
./gdrive list -q "name contains 'University'" # serch files by name
./gdrive download fileID # Download some file. You can find the fileID from the 'gdrive list' result.
./gdrive upload filename  #  Upload a local file to your google drive account.
./gdrive mkdir # Create new folder

希望这会有所帮助.

这篇关于使用 Python 下载共享的 Google Drive 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:设置“发布到网络"在 Google 电子表格中使用 下一篇:“findAll"之间的区别和“find_all"在美丽汤

相关文章

最新文章