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

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

我希望这里有人能帮忙!


当前回答

你可以从谷歌得到url下载链接…/file/d/FILEID/view?usp=share_link并提取FILEID部分。然后在下面替换它(它在那里两次)。

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 'https://docs.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

将FILENAME替换为上面一行中应该调用的文件并享受。

其他回答

——更新

要下载该文件,请从这里获取python的youtube-dl:

YouTube-DL: https://rg3.github.io/youtube-dl/download.html

或者用pip安装:

sudo python2.7 -m pip install --upgrade youtube_dl 
# or 
# sudo python3.6 -m pip install --upgrade youtube_dl

更新:

我刚刚发现了这个:

右击要从drive.google.com下载的文件 点击获取共享链接 开启链路共享 点击共享设置 点击顶部下拉菜单的选项 点击更多 选择[x]打开-任何有链接的人 复制链接

https://drive.google.com/file/d/3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR/view?usp=sharing       
(This is not a real file address)

将id复制到https://drive.google.com/file/d/:之后

3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR

粘贴到命令行:

youtube-dl https://drive.google.com/open?id=

把id贴在后面?id =

youtube-dl https://drive.google.com/open?id=3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR
[GoogleDrive] 3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR: Downloading webpage
[GoogleDrive] 3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR: Requesting source file
[download] Destination: your_requested_filename_here-3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR
[download] 240.37MiB at  2321.53MiB/s (00:01)

希望能有所帮助

谷歌硬盘也有同样的问题。

下面是我如何使用Links 2解决这个问题。

Open a browser on your PC, navigate to your file in Google Drive. Give your file a public link. Copy the public link to your clipboard (eg right click, Copy link address) Open a Terminal. If you're downloading to another PC/server/machine you should SSH to it as this point Install Links 2 (debian/ubuntu method, use your distro or OS equivalent) sudo apt-get install links2 Paste the link in to your terminal and open it with Links like so: links2 "paste url here" Navigate to the download link within Links using your Arrow Keys and press Enter Choose a filename and it'll download your file

这里有一个快速的方法。

确保链接是共享的,它看起来会像这样:

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
ggID='put_googleID_here'  
ggURL='https://drive.google.com/uc?export=download'  
filename="$(curl -sc /tmp/gcokie "${ggURL}&id=${ggID}" | grep -o '="uc-name.*</span>' | sed 's/.*">//;s/<.a> .*//')"  
getcode="$(awk '/_warning_/ {print $NF}' /tmp/gcokie)"  
curl -Lb /tmp/gcokie "${ggURL}&confirm=${getcode}&id=${ggID}" -o "${filename}"  

它是如何工作的? 使用curl获取cookie文件和html代码。 管道html到grep和sed和搜索文件名。 使用awk从cookie文件中获取确认代码。 最后下载启用cookie的文件,确认代码和文件名。

curl -Lb /tmp/gcokie "https://drive.google.com/uc?export=download&confirm=Uq6r&id=0B5IRsLTwEO6CVXFURmpQZ1Jxc0U" -o "SomeBigFile.zip"

如果你不需要文件名变量卷曲可以猜出来 -L Follow重定向 - o远程名称 - j Remote-header-name

curl -sc /tmp/gcokie "${ggURL}&id=${ggID}" >/dev/null  
getcode="$(awk '/_warning_/ {print $NF}' /tmp/gcokie)"  
curl -LOJb /tmp/gcokie "${ggURL}&confirm=${getcode}&id=${ggID}" 

要从URL提取谷歌文件ID,您可以使用:

echo "gURL" | egrep -o '(\w|-){26,}'  
# match more than 26 word characters  

OR

echo "gURL" | sed 's/[^A-Za-z0-9_-]/\n/g' | sed -rn '/.{26}/p'  
# replace non-word characters with new line,   
# print only line with more than 26 word characters 

从谷歌驱动器上下载文件的简单方法,您也可以在colab上下载文件

pip install gdown

import gdown

Then

url = 'https://drive.google.com/uc?id=0B9P1L--7Wd2vU3VUVlFnbTgtS2c'
output = 'spam.txt'
gdown.download(url, output, quiet=False)

or

fileid='0B9P1L7Wd2vU3VUVlFnbTgtS2c'

gdown https://drive.google.com/uc?id=+fileid

文档https://pypi.org/project/gdown/