問題描述
我在谷歌驅(qū)動器上有一個只有 .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.
到目前為止,我發(fā)現(xiàn)唯一有效的是下面的代碼,但我只能讓它適用于特定的共享文件,而不是整個文件夾.
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 工具.基本上它是一個從命令行訪問谷歌驅(qū)動器帳戶的工具.按照這個 Linux 機器的示例進行設(shè)置:
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:
- 首先下載gdrive的執(zhí)行文件這里.
- 解壓得到可執(zhí)行文件
gdrive
.現(xiàn)在通過執(zhí)行命令更改文件的權(quán)限chmod +x gdrive
. - 運行
./gdrive about
,你會得到一個URL,要求你輸入驗證碼.按照提示復(fù)制鏈接并轉(zhuǎn)到您的瀏覽器上的 URL,然后登錄您的 Google Drive 帳戶并授予權(quán)限.最后你會得到一些驗證碼.復(fù)制它. - 返回之前的終端,粘貼剛剛復(fù)制的驗證碼.然后驗證你的信息在那里.現(xiàn)在您已成功將您的機器鏈接到您的 Google Drive帳戶.
- At first download the execution file of gdrive here.
- Decompress it and get the executable file
gdrive
. Now change the permissions of the file by executing the commandchmod +x gdrive
. - 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. - 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.
現(xiàn)在完成上述過程后,您可以使用下面提到的命令瀏覽驅(qū)動器上的文件.
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
希望這會有所幫助.
這篇關(guān)于使用 Python 下載共享的 Google Drive 文件夾的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!