我试图在脚本中从谷歌驱动器下载一个文件,我这样做有点麻烦。我要下载的文件在这里。

我在网上搜了很多,终于下载了其中一个。我得到了文件的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,但这不起作用。

我希望这里有人能帮忙!


当前回答

无脚本方法获得直接链接

我知道一些没有bash脚本编写经验的人正在从其他网站来到这篇文章。这是一个在浏览器中完成的解决方案。

步骤1:通常使用现有工具生成直接链接

首先,您使用所有其他现有的解决方案从您的共享链接生成一个直接链接。您可以使用https://sites.google.com/site/gdocs2direct/, https://www.wonderplugin.com/online-tools/google-drive-direct-link-generator/或https://chrome.google.com/webstore/detail/drive-direct-download/mpfdlhhpbhgghplbambikplcfpbjiail。 我将忽略这部分。

生成的直接链接如下所示:https://drive.google.com/u/0/uc?id=1Gjvcfj-8xxxxxxx8G8_jpgjcyorQ7BX5&export=download

直接链接适用于大多数小文件,但不适用于大文件。它将显示病毒警告,而不是简单地下载文件。现在我们来解决这个问题。

步骤2:修复断开的直接链接以解决病毒警告

在浏览器中打开断开的“直接”链接,您将看到“谷歌驱动器无法扫描此文件的病毒”。现在右键单击并查看页面源代码,您将看到以下文本:

<form id="downloadForm" action="https://drive.google.com/u/0/uc?id=1Gjvcfj-8xxxxxxx8G8_jpgjcyorQ7BX5&amp;export=download&amp;confirm=t&amp;uuid=5a0dd46b-521e-4ae7-8b41-0912e88b7782" method="post">

你已经找到了最后的链接!替换所有&去&并享受:

https://drive.google.com/uc?id=1Gjvcfj-8xxxxxxx8G8_jpgjcyorQ7BX5&export=download&confirm=t&uuid=c953a94e-b844-479f-8386-1ec83770fffb

大文件的其他解决方案:谷歌驱动器API

这个解决方案已经有了一个很好的答案!

其他回答

有一个开源的多平台客户端,用Go: drive编写。它非常漂亮,功能齐全,而且还在积极开发中。

$ drive help pull
Name
        pull - pulls remote changes from Google Drive
Description
        Downloads content from the remote drive or modifies
         local content to match that on your Google Drive

Note: You can skip checksum verification by passing in flag `-ignore-checksum`

* For usage flags: `drive pull -h`

以上答案对于2020年4月已经过时,因为谷歌驱动器现在使用重定向到文件的实际位置。

截至2020年4月,在macOS 10.15.4上工作的公共文档:

# this is used for drive directly downloads
function download-google(){
  echo "https://drive.google.com/uc?export=download&id=$1"
  mkdir -p .tmp
  curl -c .tmp/$1cookies "https://drive.google.com/uc?export=download&id=$1" > .tmp/$1intermezzo.html;
  curl -L -b .tmp/$1cookies "$(egrep -o "https.+download" .tmp/$1intermezzo.html)" > $2;
}

# some files are shared using an indirect download
function download-google-2(){
  echo "https://drive.google.com/uc?export=download&id=$1"
  mkdir -p .tmp
  curl -c .tmp/$1cookies "https://drive.google.com/uc?export=download&id=$1" > .tmp/$1intermezzo.html;
  code=$(egrep -o "confirm=(.+)&amp;id=" .tmp/$1intermezzo.html | cut -d"=" -f2 | cut -d"&" -f1)
  curl -L -b .tmp/$1cookies "https://drive.google.com/uc?export=download&confirm=$code&id=$1" > $2;
}

# used like this
download-google <id> <name of item.extension>

使用youtube-dl !

优酷-DL https://drive.google.com/open?id=ABCDEFG1234567890

你也可以传递——get- URL来获取一个直接下载的URL。

警告:此功能已弃用。见下面评论中的警告。


看看这个问题:直接从谷歌驱动器使用谷歌驱动器API下载

基本上,你必须创建一个公共目录,并通过相对引用来访问你的文件

wget https://googledrive.com/host/LARGEPUBLICFOLDERID/index4phlat.tar.gz

或者,您可以使用这个脚本:https://github.com/circulosmeos/gdown.pl

对于无意中发现这条线索的任何人,以下工作截至2022年5月,以绕过大文件的反病毒检查:

#!/bin/bash
fileid="FILEIDENTIFIER"
filename="FILENAME"
html=`curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}"`
curl -Lb ./cookie "https://drive.google.com/uc?export=download&`echo ${html}|grep -Po '(confirm=[a-zA-Z0-9\-_]+)'`&id=${fileid}" -o ${filename}