Download Anything to Google Drive using Google Colab


Google Collab is a free online Platform provided by Google that provides CPU, GPU, and other infrastructure to run complex computation and data analysis. Google Collab provides a jupyter notebook environment to run Python code. We can download anything to google drive using google collab by mounting our google drive on Collab. In this article, we will understand how we can download anything to google drive using google collab.

Step 1: Setting up google collab

If you have a Google account you can open the google collab website and click on “New Notebook” to create a new Jupyter Notebook. To access google collab, you need to have a Google account.

Step 2: Mounting your Google Drive

To download anything to google drive using google collab you need to mount your google drive account from the google collab environment. To mount your google drive on Collab run the following code on jupyter notebook in Collab.

After running the code you will get a prompt to authenticate your Google account and allow Collab to access your drive. Follow the instructions in the prompt and complete the authentication process.

from google.collab import drive
drive.mount('/content/drive')

Output

Step 3: Downloading files to google drive

Once your drive is mounted to the collab environment you can now download files from the internet directly to your google drive by the following code syntax

Syntax

!wget -P /content/drive/My\ Drive [file URL]

Here [file URL]is the URL of the file you want to download. The !wget is used to download files from the internet and -P specifies the location where the file is stored in google drive.

Example

In the below example, we have downloaded a Python logo and saved it to the root directory of our drive.

!wget -P /content/drive/My\ Drive https://www.python.org/static/img/python-logo.png

Output

Conclusion

In this article, we discussed how we can download files from the internet directly to our google drive. To download anything to our google drive we need to mount our google drive in a collab environment. Once the drive is mounted in Collab then we can download any file to the drive by using wget command.

Updated on: 10-Jul-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements