【发布时间】:2020-06-09 14:46:28
【问题描述】:
我一直在使用此代码通过 Google Drive 安装 Colab,并通过粘贴下载 URL 来下载任何文件,但我注意到即使文件只有几兆字节,它也需要很长时间。有什么可以改进的吗?
**First cell:**
from google.colab import drive
drive.mount('/content/gdrive')
root_path = 'gdrive/My Drive/'
**Second cell:**
import requests
file_url = "DOWNLOAD URL HERE"
r = requests.get(file_url, stream = True)
with open("/content/gdrive/My Drive/FILE NAME HERE", "wb") as file:
for block in r.iter_content(chunk_size = 1024):
if block:
file.write(block)
【问题讨论】:
标签: python download google-colaboratory