首页 > 其他分享 >通过命令行从 Google Drive下载数据

通过命令行从 Google Drive下载数据

时间:2023-02-18 12:32:53浏览次数:56  
标签:cookies Google https -- Drive drive google 命令行 com

分享链接

Google Drive的分享链接格式通常为:

https://drive.google.com/file/d/<fileid>/view

其中这个​​<fileid>​​就是对应文件在服务器上的唯一标识符。

例如VA数据集在Google Drive上的链接即为:

https://drive.google.com/file/d/1q3M_73LRH7jwJpdfKUV2Xg7Wy3YUKY2x/view

其中的​​<fileid>​​​为​​1q3M_73LRH7jwJpdfKUV2Xg7Wy3YUKY2x​​,文件名可以自己取。

所以提取到的关键变量为:

filename='VA.zip'
fileid='1q3M_73LRH7jwJpdfKUV2Xg7Wy3YUKY2x'

wget 下载指令

针对小文件:

wget --no-check-certificate "https://drive.google.com/uc?export=download&id=${fileid}" -O ${filename}

即为:

​​wget --no-check-certificate "​​​​https://drive.google.com/uc?export=download&id=${'1q3M_73LRH7jwJpdfKUV2Xg7Wy3YUKY2x'}​​" -O ${'VA.zip'}​

如果文件大的话,需要对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

整理成更方便的shell脚本示例为:

xxxx.sh

# 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

​Gdown下载

如果采用Gdown下载(​​pip install gdown​​安装)命令行为

gdown 'https://drive.google.com/uc?id=FILE_ID'
gdown 'https://drive.google.com/uc?id=1q3M_73LRH7jwJpdfKUV2Xg7Wy3YUKY2x'

问题:

连接不上网络。

通过命令行从 Google Drive下载数据_服务器

待解决。。。

参考文章:

​通过命令行从 Google Drive下载数据​

​离线服务器通过PC中转连接公网​

标签:cookies,Google,https,--,Drive,drive,google,命令行,com
From: https://blog.51cto.com/u_12074581/6065311

相关文章