推荐:Linux下使用gdown来下载Google Drive谷歌云盘教程
-----
Google Drive的分享链接格式通常为:
https://drive.google.com/file/d/<fileid>/view
其中这个<fileid>
就是对应文件在服务器上的唯一标识符。
例如OfficeHome数据集在Google Drive上的链接即为:
https://drive.google.com/file/d/0B81rNlvomiwed0V1YUxQdC1uOTg/view
其中的<fileid>
为0B81rNlvomiwed0V1YUxQdC1uOTg
,文件名可以自己取。
所以提取到的关键变量为:
filename='OfficeHomeDataset_10072016.zip'
fileid='0B81rNlvomiwed0V1YUxQdC1uOTg'
wget 指令
针对小文件:
wget --no-check-certificate "https://drive.google.com/uc?export=download&id=${fileid}" -O ${filename}
如果文件大的话,需要对cookie进行处理:
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://drive.google.com/uc?export=download&id=${fileid}' -O- | sed -rn 's/.confirm=([0-9A-Za-z_]+)./\1\n/p')&id=${fileid}" -O ${filename} && rm -rf /tmp/cookies.txt
整理成脚本:
# cd scratch place
cd data/
# Download zip dataset from Google Drive
filename='OfficeHomeDataset_10072016.zip'
fileid='0B81rNlvomiwed0V1YUxQdC1uOTg'
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://drive.google.com/uc?export=download&id=${fileid}' -O- | sed -rn 's/.confirm=([0-9A-Za-z_]+)./\1\n/p')&id=${fileid}" -O ${filename} && rm -rf /tmp/cookies.txt
# Unzip
unzip -q ${filename}
rm ${filename}
cd
谷歌获取下载链接的方式:
有时候需要修改权限:
改成所有人可下载