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

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

我希望这里有人能帮忙!


当前回答

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


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

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

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

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

其他回答

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) 您应该将目标文件的权限从“受限”更改为“任何拥有该链接的人”。

简单的方法:

(如果你只需要一次性下载)

去谷歌驱动器的网页,有下载链接 打开浏览器控制台,转到“网络”选项卡 点击下载链接 等待它的文件开始下载,并找到相应的请求(应该是列表中的最后一个),然后可以取消下载 右键单击请求并单击“复制为cURL”(或类似的)

你应该得到如下内容:

curl 'https://doc-0s-80-docs.googleusercontent.com/docs/securesc/aa51s66fhf9273i....................blah blah blah...............gEIqZ3KAQ==' --compressed

在控制台中,添加> my-file-name。扩展到最后(否则它会把文件写到你的控制台),然后按enter:)

这个链接确实有某种过期时间,所以在生成第一个请求后几分钟就不能开始下载了。

从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)。

这是我从谷歌驱动器下载文件到我的谷歌云Linux外壳的解决方案。

使用高级共享将文件共享给PUBLIC并具有Edit权限。 你会得到一个共享链接,它会有一个ID。参见链接:- drive.google.com/file/d/ (ID) /视图? usp =分享 复制该ID并粘贴在以下链接:-

googledrive.com/host/ (ID)

以上链接为我们的下载链接。 使用wget下载文件:-

wget https://googledrive.com/host/ [ID]

该命令将下载名称为[ID]的文件,没有扩展名,但文件大小与运行wget命令的位置相同。 实际上,我在实习时下载了一个压缩文件夹。所以我重命名了这个尴尬的文件使用:-

mv [id] 1.zip

然后使用

1.压缩解压缩

我们会拿到文件的。

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

下面是我如何使用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