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

我在网上搜了很多,终于下载了其中一个。我得到了文件的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脚本,它今天完成了这项工作。它适用于大文件,也可以恢复部分获取的文件。它有两个参数,第一个是file_id,第二个是输出文件的名称。与之前的答案相比,主要的改进是它可以在大文件上工作,只需要常用的工具:bash, curl, tr, grep, du, cut和mv。

#!/usr/bin/env bash
fileid="$1"
destination="$2"

# try to download the file
curl -c /tmp/cookie -L -o /tmp/probe.bin "https://drive.google.com/uc?export=download&id=${fileid}"
probeSize=`du -b /tmp/probe.bin | cut -f1`

# did we get a virus message?
# this will be the first line we get when trying to retrive a large file
bigFileSig='<!DOCTYPE html><html><head><title>Google Drive - Virus scan warning</title><meta http-equiv="content-type" content="text/html; charset=utf-8"/>'
sigSize=${#bigFileSig}

if (( probeSize <= sigSize )); then
  virusMessage=false
else
  firstBytes=$(head -c $sigSize /tmp/probe.bin)
  if [ "$firstBytes" = "$bigFileSig" ]; then
    virusMessage=true
  else
    virusMessage=false
  fi
fi

if [ "$virusMessage" = true ] ; then
  confirm=$(tr ';' '\n' </tmp/probe.bin | grep confirm)
  confirm=${confirm:8:4}
  curl -C - -b /tmp/cookie -L -o "$destination" "https://drive.google.com/uc?export=download&id=${fileid}&confirm=${confirm}"
else
  mv /tmp/probe.bin "$destination"
fi

其他回答

2022年4月

首先,从谷歌驱动器中提取所需文件的ID: 在浏览器中,导航到drive.google.com。 右键单击文件,点击“获取可共享链接” 然后从URL中提取文件的ID: 接下来,使用pip安装gdown PyPI模块: PIP安装gdown 最后,使用gdown和预期的ID下载文件: gdown——id <put-the-ID>


【注意】:

在google-colab你必须使用!在bash命令之前。 (即!gdown——id 1-1wAx7b-USG0eQwIBVwVDUl3K1_1ReCt) 您应该将目标文件的权限从“受限”更改为“任何拥有该链接的人”。

这里有一个快速的方法。

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

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

我使用这个小脚本,只得到从谷歌驱动器复制的URL:

#!/bin/bash

name=`curl $1 |  grep -w \"name\" | sed 's/.*"name" content="//' | 
sed 's/".*//'`
id=`echo $1 | sed 's#.*/d/##; s#/view.*##'`
curl -L https://drive.google.com/uc?id=$id > $name
# or
# wget -O $name https://drive.google.com/uc?id=$id

您可以安装“lynx”,在“lynx”的帮助下,您可以轻松下载文件。

yum install lynx

将ID_OF_FILE替换为文件的id

lynx https://drive.google.com/u/0/uc?id=ID_OF_FILE&export=download

然后选择“下载”或“随便下载”

就是这样

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

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

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

使用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