Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   1722

How to download Anything to GDrive using Google Colab

by cenahum - 24 October, 2019 - 01:11 PM
This post is by a banned member (cenahum) - Unhide
cenahum  
Registered
83
Posts
21
Threads
5 Years of service
#1
For newbee like me

I'm studying colab and at first i learned how to download torrent files for gdrive but what i didn't see in any forum was how to download files from the internet to gdrive using colab.
Now you can see here how to use Colab to do downloads from Internet sites to Gdrive, you will use Colab resources not yours.

When we download/upload something from a cloud server, it gives more transfer rate as compared to a normal server. We can use Google Drive for storage as well as fast speed download. The problem is how to upload something to G-Drive direct from Internet. So, Here we will see a solution to upload anything to Google drive directly from Internet.

All we need is google account and a few lines of code.

Google Colab is a free cloud service with GPU support. It is like Jupyter Notebook and very simple to use. In this tutorial, we will be using Google Colab to download anything to our google drive.

Step #1 : Sign in to Google Colab and Create a new Python3 notebook

[Image: salve_tudo_1.png?1571913756]


[Image: salve_tudo_2.png?1571913810]

Step #2 : Importing google drive to colab

To import google drive, write this code in code section of colab and run it by Ctrl+Enter.

filter_none
brightness_4
from google.colab import drive 
drive.mount('/content/gdrive')

[Image: salve_tudo_3.png?157191389]



[Image: salve_tudo_4.png?1571913932]

On running code, one blue link and a text box will appear we need to provide a permission text. So click the link and a new tab will open where you will be asked for permission to access google drive. After providing permissions a text will be displayed that we need to Copy and paste on colabs text box.

[Image: salve_tudo_5.png?1571913958]


Paste text in box and press enter. That all to import gdrive. We can see google drive on Left side Panel.

[Image: salve_tudo_6.png?1571913981]


Step #3 : Download something to Google Drive

To download something all we need is URL to downloadable file.

filter_none
brightness_4
import requests  
file_url = "http://1.droppdf.com/files/5iHzx/automate-the-boring-stuff-with-python-2015-.pdf"
    
r = requests.get(file_url, stream = True)  
  
with open("/content/gdrive/My Drive/python.pdf", "wb") as file:  
    for block in r.iter_content(chunk_size = 1024): 
         if block:  
             file.write(block)

[Image: salve_tudo_7.png?1571914008]

We can see on the left side panel that PDF file is downloaded.

You can download files and or an entire directory with sub dir included.

Material source:Geeks for Geeks
This post is by a banned member (Newtingz) - Unhide
Newtingz  
Registered
15
Posts
0
Threads
4 Years of service
#2
Thanks man I've been looking for something like this for long since my schoolw WiFi is fully compatible with anything Google download from any Google related site or so are flying

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)