我有一个脚本,它从谷歌驱动器中获取文件列表
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
gauth.Refresh()
else:
gauth.Authorize()
gauth.SaveCredentialsFile("mycreds.txt")
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
folder = "1CNtWRS005fkX6vlZowZiXYITNGifXPKS"
file_list = drive.ListFile({'q': f"'{folder}' in parents"}).GetList()
for file in file_list:
print(file['title'])
-> 1.txt
它只从磁盘接收数据,但我需要脚本从它可以访问的文件夹接收文件列表——";可供我使用";。我有一个文件夹ID,但如果我在folder
字段中替换它,就不会发生任何事情
我认为gdown可以帮助您。
pip安装gdown
然后可以尝试这样的东西:
import gdown
id = "folderId..."
gdown.download_folder(id=id, quiet=True, use_cookies=False)