3

Suppose that someone gives me a link that enables me to download a public file in Google Drive.

I want to write a program that can read the link and then download it as a text file.

For example, https://docs.google.com/document/d/1yJVXtabsP7KrJXSu3XyOh-F2cFoP8Lftr14PtXCLEVU/edit is one of files in my Google Drive. Everyone can access this file.

But how can I write a Python program that downloads the text file given the above link?

Could someone have some pieces of sample code for me?

It seems that some Google Drive SDK could be useful(?), but is there any way to do it without using SDK?

4

2 回答 2

4

首先,您需要编写一个程序来切断您上传的文件的链接。例如在您提供的链接中: https ://docs.google.com/document/d/1yJVXtabsP7KrJXSu3XyOh-F2cFoP8Lftr14PtXCLEVU/edit

id 是1yJVXtabsP7KrJXSu3XyOh-F2cFoP8Lftr14PtXCLEVU

将其保存在某个变量中,现在说 download_link 以获取下载链接: https ://docs.google.com/uc?export=download&id= download_link 此链接将下载文件

于 2013-05-11T12:39:54.950 回答
0

如果上述答案对您不起作用,请使用以下链接:

保存为 .txt 文件: https ://docs.google.com/document/d/1yJVXtabsP7KrJXSu3XyOh-F2cFoP8Lftr14PtXCLEVU/export?format=txt

保存为 docx 文件: https ://docs.google.com/document/d/1yJVXtabsP7KrJXSu3XyOh-F2cFoP8Lftr14PtXCLEVU/export?format=docx

通常,诀窍是添加:export?format=txt 而不是编辑!希望能帮助到你。

于 2021-06-19T22:53:23.140 回答