使用 wget 从 Google Drive 下载账户受限文件时出错。我收到“结果太大”的错误

使用 wget 从 Google Drive 下载账户受限文件时出错。我收到“结果太大”的错误

如何使用 wget 从 Google Drive 下载文件?

我想要下载的文件是帐户限制的,这意味着只有拥有特定 Google 帐户的人才能访问该文件。(即,通过右键单击文件并单击共享并选择选项将文件设置为受限,这样只有特定的 Google 帐户电子邮件地址才能访问它,因此只有以该身份登录的人才能访问它)

在这种特殊情况下,将文件设置为“所有人”对我来说并不是一个真正的选择。(为什么,是另一回事!)。我知道如果将文件设置为“所有人”,那么 wget 可以下载它。

我登录了我的 Google 帐户,即可以访问该文件的帐户,然后我转到我登录的 Google.com,并使用 cookie 编辑器扩展https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm 我将 cookie 导出到剪贴板,将其粘贴到记事本中的文件中并保存。

C:\blah>wget --no-check-certificate --load-cookies .\cook.txt url  

我收到“结果太大”的错误(与我尝试在没有 --load-cookies 的情况下尝试该命令时遇到的错误相同。\cook.txt

首先,如果我将其设置为每个人(我只是暂时测试一下),那么它就可以工作了

O:\abc>wget --no-check-certificate https://drive.google.com/file/d/1fo...YB/view?usp=sharing
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
--2022-10-15 09:27:59--  https://drive.google.com/file/d/1f...YB/view?usp=sharing
Resolving drive.google.com... 142.250.187.238
Connecting to drive.google.com|142.250.187.238|:443... connected.
WARNING: cannot verify drive.google.com's certificate, issued by `/C=US/O=Google Trust Services LLC/CN=GTS CA 1C3':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `view@usp=sharing.1'

    [ <=>                                                                                               ] 67,696      --.-K/s   in 0.02s

2022-10-15 09:27:59 (4.01 MB/s) - `view@usp=sharing.1' saved [67696]

注意有一个警告“警告:无法验证 drive.google.com 的证书”,但没关系我仍然可以下载它。

没有错误提示“结果太大”。因此问题具体出在文件受到限制时。

而且文件也不大,只有 78MB。所以文件大小不是问题,与任何问题都无关。

如果文件设置为仅供特定 gmail 帐户使用,那么如果可以使用 wget 下载,我必须加载 cookie。我已经按照我描述的方式创建了一个 cookie/cookies 文件。然后尝试用它运行 wget,但它不起作用。事实上,即使我在没有 --load-cookies 的情况下执行 wget,我也会得到同样的错误“结果太大”。

O:\abc>dir cook.txt
 Volume in drive O is TOSHIBA EXT
 Volume Serial Number is E05E-F917

 Directory of O:\abc

15/10/2022  09:15             8,699 cook.txt
               1 File(s)          8,699 bytes
               0 Dir(s)  3,946,736,459,776 bytes free

然后我运行命令

O:\abc>wget --load-cookies .\cook.txt https://drive.google.com/file/d/1.....YB/view?usp=sharing

输出看起来与我没有使用 --load-cookies 执行命令时的输出大致相同。\cook.txt

SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
--2022-10-15 09:39:12--  https://drive.google.com/file/d/1f...B/view?usp=sharing
Resolving drive.google.com... 142.250.187.238
Connecting to drive.google.com|142.250.187.238|:443... connected.
WARNING: cannot verify drive.google.com's certificate, issued by `/C=US/O=Google Trust Services LLC/CN=GTS CA 1C3':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://accounts.google.com/ServiceLogin?service=wise&passive=1209600&osid=1&continue=https://drive.google.com/file/d/1fo7.....YB/view?usp%3Dsharing&followup=https://drive.google.com/file/d/1f....YB/view?usp%3Dsharing [foll
owing]
--2022-10-15 09:39:12--  https://accounts.google.com/ServiceLogin?service=wise&passive=1209600&osid=1&continue=https://drive.google.com/file
/d/1f....zYB/view?usp%3Dsharing&followup=https://drive.google.com/file/d/1....YB/view?usp%
3Dsharing
Resolving accounts.google.com... 142.250.200.13
Connecting to accounts.google.com|142.250.200.13|:443... connected.
WARNING: cannot verify accounts.google.com's certificate, issued by `/C=US/O=Google Trust Services LLC/CN=GTS CA 1C3':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://accounts.google.com/v3/signin/identifier?dsh=S-33.....71&continue=https%3A%2F%2Fdrive.google.com%2Ffile%
2Fd%2F1.....YB%2Fview%3Fusp%3Dsharing&followup=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd.....p%3Dsharing&osid=1&passive=1209600&service=wise&flowName=WebLiteSignIn&flowEntry=ServiceLogin&ifkv=AQD.....0yX_P [following]
--2022-10-15 09:39:13--  https://accounts.google.com/v3/signin/identifier?dsh=S-33.....71&continue=https%3A%2F%2Fdrive.goo
gle.com%2Ffil.....w%3Fusp%3Dsharing&followup=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1fo7RdB68
uFZ27nIHJCffMPgzXSlcOzYB%2Fview%3Fusp%3Dsharing&osid=1&passive=1209600&service=wise&flowName=WebLiteSignIn&flowEntry=ServiceLogin&ifkv=AQDHY
Wq.....iRl0yX_P
Reusing existing connection to accounts.google.com:443.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
identifier@dsh=S-33....871&continue=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1fo7RdB...zYB%2Fview%3
Fusp=sharing&followup=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1fo....OzYB%2Fview%3Fusp=sharing&osid=1&passive=1209
600&service=wise&flowName=WebLiteSignIn&flowEntry=ServiceLogin&ifkv=AQD....c9fFNx458..R1XjInhWResi7WO..Rl0
yX_P: No such file or directory

Cannot write to `identifier@dsh=S-332...0%3A1...871&continue=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F....gz
XSlc..2Fview%3Fusp=sharing&followup=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1f....HJCff..XSlcOzYB%2Fview%3Fusp=sharing&os
id=1&passive=12..&service=wise&flowName=WebLiteSignIn&flowEntry=ServiceLogin&ifkv=AQDHYW.....InhW
Resi7WO....yX_P' (Result too large).

该输出的错误和警告是

WARNING: cannot verify drive.google.com's certificate, issued by `/C=US/O=Google Trust Services LLC/CN=GTS CA 1C3':
      Unable to locally verify the issuer's authority.
    HTTP request sent, awaiting response... 302 Moved Temporarily
......
    WARNING: cannot verify accounts.google.com's certificate, issued by `/C=US/O=Google Trust Services LLC/CN=GTS CA 1C3':
      Unable to locally verify the issuer's authority.
............
 No such file or directory
   
    Cannot write to `identifier@dsh
.......
(Result too large).

我如何使用 wget 下载它?

我还没有测试过 curl 但是这个问题与 wget 有关。

添加

稍微更正一下...即使链接是发给所有人的,实际下载的只是一个包含 HTML/Javascript 内容的 65KB 文件。

O:\abc>dir
 Volume in drive O is TOSHIBA EXT
 Volume Serial Number is E05E-F917

 Directory of O:\abc

...
15/10/2022  09:27            67,695 view@usp=sharing
....
O:\abc>

O:\abc>file "view@usp=sharing"
view@usp=sharing: HTML document, ASCII text, with very long lines (16533)

O:\abc>

有一个程序叫 gdownhttps://github.com/wkentaro/gdown 尽管据我所知,它可以下载 Google Drive 链接,但你不能传递 cookie 并下载只有特定的 Gmail 帐户才能访问的文件。

更多信息

这可能是一种解决方法,尽管我还没有测试过https://medium.com/@acpanjan/download-google-drive-files-using-wget-3c2c025a8b99 可能的来源是来自名为“iamtekeste”的用户页面的此链接https://gist.github.com/iamtekeste/3cdfd0366ebfd2c0d805 来自一位名叫 beliys 的评论者

中等链接提到重新排列 URL,例如

https://drive.google.com/file/d/1UibyVC_C2hoT_XEw15gPEwPW4yFyJFeOEA/view?usp=sharing

(移动文件 ID),

https://docs.google.com/uc?export=download&id=FILEID

然后 wget 就可以工作了..然后可以尝试加载 cookies,对于需要登录谷歌账户的文件,但尚未测试。

我注意到中等链接中的建议涉及一个命令行,即 $(..) ,bash 样式的命令替换,因此由于 bash 更容易成为 Linux 的东西而不是 Windows 的东西,我在 ubuntu 中测试了那里建议的命令。

https://medium.com/@acpanjan/download-google-drive-files-using-wget-3c2c025a8b99

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

当所有人都可以访问该文件时,它就会下载该文件。

当文件无法被所有人访问时,它会下载一个 139KB 的 HTML 文件,这是 Google 登录页面。如果您尝试访问该文件但未登录,则在网络浏览器中会看到相同的页面

github 上的“iamtekeste”页面上有一条来自 LL3RD 的评论,其中提到 https://stackoverflow.com/questions/65312867/how-to-download-large-file-from-google-drive-from-terminal-gdown-doesnt-work 我还没有尝试过,但会尝试

相关内容