如何通过 curl 或 wget 下载 Google Drive url [英] How to download a Google Drive url via curl or wget

查看:60
本文介绍了如何通过 curl 或 wget 下载 Google Drive url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 curl 或 wget 下载可公开查看的 Google Drive 网址?例如,能够执行以下操作:

Is there a way to download a publicly-viewable Google Drive url via curl or wget? For example, being able to do something like:

curl -O myfile.xls https://drive.google.com/uc?export=download&id=1Wb2NfKTQr_dLoFJH0GfM0cx-t4r07IVl

请注意,我希望在一个可公开查看的文件中执行此操作,而无需登录我的 Google 帐户(或让其他人登录他们的帐户等).

Note, I'm looking to do this on a publicly-viewable file without having to sign into my Google account (or have someone else sign into their account, etc.).

如果有帮助,我的 cors 标题是:

If helpful, the cors headers I have are:

 "kind": "drive#file",
 "id": "1Wb2NfKTQr_dLoFJH0GfM0cx-t4r07IVl",

推荐答案

这个方法怎么样?当文件如此大时,Google 会返回下载文件的代码.您可以使用代码下载文件.使用curl下载这么大的文件时,可以看到如下代码.

How about this method? When the file is such large size, Google returns a code for downloading the file. You can download the file using the code. When such large file is downloaded using curl, you can see the code as follows.

<a id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" href="/uc?export=download&amp;confirm=ABCD&amp;id=### file ID ###">download</a>

带有confirm=ABCD 的查询对于下载文件很重要.此代码也包含在 cookie 中.在cookie处,可以看到如下.

The query with confirm=ABCD is important for downloading the file. This code is also included in the cookie. At the cookie, you can see it as follows.

#HttpOnly_.drive.google.com TRUE    /uc TRUE    #####   download_warning_#####  ABCD

在这种情况下,ABCD"是代码.为了从cookie中检索代码并下载文件,您可以使用以下脚本.

In this case, "ABCD" is the code. In order to retrieve the code from the cookie and download the file, you can use the following script.

#!/bin/bash
fileid="### file id ###"
filename="MyFile.csv"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}

如果这对您没有用,我很抱歉.

If this was not useful for you, I'm sorry.

这篇关于如何通过 curl 或 wget 下载 Google Drive url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆