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

我在网上搜了很多,终于下载了其中一个。我得到了文件的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年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}

其他回答

获取文件ID:

1.在浏览器中打开谷歌驱动器。

2.右键单击要下载的文件,单击“获取可共享链接”。链接如下所示:https://drive.google.com/file/d/XXX/view?usp=sharing。记录文件ID XXX;你将在下面需要它。

获取一个OAuth令牌:

1.去OAuth 2.0游乐场

2.在“选择和授权API”框中,向下滚动,展开Drive API v3,并选择https://www.googleapis.com/auth/drive.readonly。

3.单击“授权api”,然后为令牌交换授权代码。复制Access令牌YYY;你将在下面需要它。

从命令行下载文件:

如果操作系统为OS X或Linux,打开“终端”程序,输入以下命令。

curl -H "Authorization: Bearer YYY" https://www.googleapis.com/drive/v3/files/XXX?alt=media -o ZZZ 

如果使用Windows操作系统,打开PowerShell程序,输入以下命令。

Invoke-RestMethod -Uri https://www.googleapis.com/drive/v3/files/XXX?alt=media -Method Get Headers @{"Authorization"="Bearer YYY"} -OutFile ZZZ

在您的命令中,将XXX替换为上面的文件ID, YYY替换为上面的访问令牌,ZZZ替换为将保存的文件名(例如,如果您下载的是zip文件,则替换为“myFile.zip”)。

在弄了这些垃圾之后。我找到了一种方法来下载我的甜蜜文件使用chrome开发工具。

At your google docs tab, Ctr+Shift+J (Setting --> Developer tools) Switch to Network tabs At your docs file, click "Download" --> Download as CSV, xlsx,.... It will show you the request in the "Network" console Right click -> Copy -> Copy as Curl Your Curl command will be like this, and add -o to create a exported file. curl 'https://docs.google.com/spreadsheets/d/1Cjsryejgn29BDiInOrGZWvg/export?format=xlsx&id=1Cjsryejgn29BDiInOrGZWvg' -H 'authority: docs.google.com' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (X..... -o server.xlsx

解决了!

谷歌驱动器的默认行为是扫描文件的病毒,如果文件太大,它将提示用户,并通知他,该文件无法扫描。

目前我找到的唯一解决办法是在网络上共享文件并创建一个网络资源。

引用自谷歌驱动器帮助页面:

使用Drive,您可以使web资源-如HTML, CSS和Javascript文件-可作为网站查看。

使用Drive托管网页:

Open Drive at drive.google.com and select a file. Click the Share button at the top of the page. Click Advanced in the bottom right corner of the sharing box. Click Change.... Choose On - Public on the web and click Save. Before closing the sharing box, copy the document ID from the URL in the field below "Link to share". The document ID is a string of uppercase and lowercase letters and numbers between slashes in the URL. Share the URL that looks like "www.googledrive.com/host/[doc id] where [doc id] is replaced by the document ID you copied in step 6. Anyone can now view your webpage.

在这里找到:https://support.google.com/drive/answer/2881970?hl=en

例如,当你在谷歌驱动器上公开共享一个文件时,共享链接看起来是这样的:

https://drive.google.com/file/d/0B5IRsLTwEO6CVXFURmpQZ1Jxc0U/view?usp=sharing

然后复制文件id,创建googledrive.com链接,如下所示:

https://www.googledrive.com/host/0B5IRsLTwEO6CVXFURmpQZ1Jxc0U

根据Roshan Sethia的回答

2018年5月

使用WGET:

Create a shell script called wgetgdrive.sh as below: #!/bin/bash # Get files from Google Drive # $1 = file ID # $2 = file name URL="https://docs.google.com/uc?export=download&id=$1" wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate $URL -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=$1" -O $2 && rm -rf /tmp/cookies.txt Give the right permissions to execute the script In terminal, run: ./wgetgdrive.sh <file ID> <filename> for example: ./wgetgdrive.sh 1lsDPURlTNzS62xEOAIG98gsaW6x2PYd2 images.zip

2020年11月

如果你更喜欢使用bash脚本,这对我来说是有效的: (5Gb文件,已公开)

#!/bin/bash
if [ $# != 2 ]; then
echo "Usage: googledown.sh ID save_name"
exit 0
fi
confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$1 -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
echo $confirm
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$confirm&id=$1" -O $2 && rm -rf /tmp/cookies.txt