我试图在脚本中从谷歌驱动器下载一个文件,我这样做有点麻烦。我要下载的文件在这里。
我在网上搜了很多,终于下载了其中一个。我得到了文件的uid,较小的文件(1.6MB)下载正常,但较大的文件(3.7GB)总是重定向到一个页面,询问我是否想在不进行病毒扫描的情况下继续下载。谁能帮我跳过那个屏幕?
下面是我如何让第一个文件工作-
curl -L "https://docs.google.com/uc?export=download&id=0Bz-w5tutuZIYeDU0VDRFWG9IVUE" > phlat-1.0.tar.gz
当我对另一个文件进行同样操作时,
curl -L "https://docs.google.com/uc?export=download&id=0Bz-w5tutuZIYY3h5YlMzTjhnbGM" > index4phlat.tar.gz
我得到以下输出-
我注意到在链接的第三行到最后一行,有一个&confirm=JwkK,这是一个随机的4个字符的字符串,但建议有一种方法添加到我的URL确认。我访问的一个链接建议&confirm=no_antivirus,但这不起作用。
我希望这里有人能帮忙!
从2022年开始,你可以使用这个解决方案:
https://drive.google.com/uc?export=download&id=FILE_ID&confirm=t
“病毒扫描警告页面”的来源:
“下载无论如何”的表单张贴到相同的URL,但有额外的三个参数:
t
确认
uuid
如果你改变你原来的URL并添加其中一个:confirm=t,它将下载文件而没有警告页面。
把URL改成
https://drive.google.com/uc?export=download&id=FILE_ID&confirm=t
例如:
$ curl -L 'https://drive.google.com/uc?export=download&id=FILE_ID' > large_video.mp4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2263 0 2263 0 0 5426 0 --:--:-- --:--:-- --:--:-- 5453
添加confirm=t后,结果为:
$ curl -L 'https://drive.google.com/uc?export=download&id=FILE_ID&confirm=t' > large_video.mp4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 128M 100 128M 0 0 10.2M 0 0:00:12 0:00:12 --:--:-- 10.9M
这里有一个快速的方法。
确保链接是共享的,它看起来会像这样:
https://drive.google.com/open?id=FILEID&authuser=0
然后,复制该FILEID并像这样使用它
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O FILENAME
如果文件很大并且触发了病毒检查页面,您可以使用这样做(但它会下载两个文件,一个html文件和实际文件):
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -r -A 'uc*' -e robots=off -nd
从2022年3月开始,你可以使用开源的跨平台命令行工具gdrive。与其他解决方案相比,它还可以不受限制地下载文件夹,也可以使用非公共文件。
来源:我从Tobi对另一个答案的评论中发现了gdrive。
当前状态
以前有问题,这个工具没有被谷歌验证,它没有维护。自2021-05-28提交以来,这两个问题都已解决。这也意味着,以前需要谷歌服务帐户的解决方案不再需要。(在极少数情况下,您可能仍会遇到问题;如果是,请尝试ntechp-fork。)
安装gdrive
下载2.1.1二进制文件。选择适合您的操作系统的软件包,例如gdrive_2.1.1 1_linux_amd64.tar.gz。
将其复制到您的路径。
gunzip gdrive_2.1.1_linux_amd64.tar.gz
Sudo mkdir /usr/local/bin/gdrive
Sudo cp gdrive-linux-amd64 /usr/local/bin/gdrive
Sudo chmod a+x /usr/local/bin/gdrive
使用gdrive
Determine the Google Drive file ID. For that, right-click the desired file in the Google Drive website and choose "Get Link …". It will return something like https://drive.google.com/open?id=0B7_OwkDsUIgFWXA1B2FPQfV5S8H. Obtain the string behind the ?id= and copy it to your clipboard. That's the file's ID.
Download the file. Of course, use your file's ID instead in the following command.
gdrive download 0B7_OwkDsUIgFWXA1B2FPQfV5S8H
At first usage, the tool will need to obtain access permissions to the Google Drive API. For that, it will show you a link which you have to visit in a browser, and then you will get a verification code to copy&paste back to the tool. The download then starts automatically. There is no progress indicator, but you can observe the progress in a file manager or second terminal.
额外的技巧:速率限制。要以有限的最大速率下载gdrive(以不淹没本地网络中的上行链路…),您可以使用这样的命令:
gdrive download --stdout 0B7_OwkDsUIgFWXA1B2FPQfV5S8H | \
pv -br -L 90k | cat > file.ext
pv是PipeViewer。该命令将显示下载的数据量(-b)和下载速率(-r),并将下载速率限制为90kib /s (-L 90k)。