下载本地Google Drive文档的HTML失败
我尝试用这个 Python 函数下载 Google Drive 上的文档(通过一个 Drive 应用)。每次都会跳到 # 文件在 Drive 上没有存储任何内容
的那部分。
def download_file(service, drive_file):
"""Download a file's content.
Args:
service: Drive API service instance.
drive_file: Drive File instance.
Returns:
File's content if successful, None otherwise.
"""
download_url = drive_file.get('downloadUrl')
if download_url:
resp, content = service._http.request(download_url)
if resp.status == 200:
print 'Status: %s' % resp
return content
else:
print 'An error occurred: %s' % resp
return None
else:
# The file doesn't have any content stored on Drive.
return None
但是我从来没有获取到 Google Drive 文档的 HTML 内容。我的 MIME 设置(HTML MIME 类型)是不是有问题,还是说我应该使用其他的 API 函数呢?
1 个回答
2
你需要导出谷歌文档,而不是下载它。可以查看一下谷歌云盘的文档,了解如何导出文件,你需要把你的网址换成类似下面的格式:
download_url = file['exportLinks']['text/html']