解决了,通过这个帖子 https://www.matthuisman.nz/2019/01/download-google-drive-files-wget-curl.html:你只需要从url中提取“文件id”!
如果分享网址是https://colab.research.google.com/drive/1SxJJc6LsKrjWAM-HhwPrLJBpUzImO5oX?usp=sharing https://colab.research.google.com/drive/1SxJJc6LsKrjWAM-HhwPrLJBpUzImO5oX?usp=sharing
那么 fileid 就是“drive/”和问号之间的所有内容。
一个 bash 的小例子...
$ export fileid=1SxJJc6LsKrjWAM-HhwPrLJBpUzImO5oX
$ wget -O downloaded_file.ipynb 'https://docs.google.com/uc?export=download&id='$fileid
...结果是 download_file.ipynb 中的有效 Jupyter 文件。 :-)
将这一切放在方便的地方bash
函数可以如下所示:
grabcolab() { fileid=$( echo "$1" | sed -E 's/.*drive\/(.*)\?.*/\1/' ); wget -O colab.ipynb 'https://docs.google.com/uc?export=download&id='$fileid; }
然后我们就跑grabcolab <sharing url>
as in:
grabcolab https://colab.research.google.com/drive/1SxJJc6LsKrjWAM-HhwPrLJBpUzImO5oX?usp=sharing
PS- 题外话,但如果你愿意的话run从命令行的笔记本,jupytext
(可通过安装pip install jupytext
)对我来说比jupyter notebook --to-script
,所以我用来运行笔记本的是
nbrun() { jupyter nbconvert --to script "$1"; mv "${1%.*}".py run_this.ipy; ipython run_this.ipy;}
As in
$ grabcolab https://colab.research.google.com/drive/1SxJJc6LsKrjWAM-HhwPrLJBpUzImO5oX?usp=sharing
$ nbrun colab.ipynb