DEV Community

Junaid
Junaid

Posted on

File downloader in python and Google Colab

This is the code for downloading files from internet.

In python (Local computer)

First install requests

pip install requests
Enter fullscreen mode Exit fullscreen mode
import requests

image_url = input("Paste your file url : ")
saveAs = input("Save As : ")
r = requests.get(image_url)

print("\nDownloading Files...\n")

with open(saveAs, "wb") as foo:
    foo.write(r.content)
    print("\nFile has been saved\n")


Enter fullscreen mode Exit fullscreen mode

In Google Colab

import requests

image_url = "https://example.com/file.png" # Paste file url here

r = requests.get(image_url)

print("\nDownloading Files...\n")

# Enter your file name ⬇⬇
with open("exampleFile.png", "wb") as foo:
    foo.write(r.content)
    print("\nFile has been saved\n")
Enter fullscreen mode Exit fullscreen mode

For reference

import requests

image_url = input("Paste your file url : ")
saveAs = input("Save As : ")
r = requests.get(image_url)

print("\nDownloading Files...\n")

with open(saveAs, "wb") as foo:
    foo.write(r.content)
    print("\nFile has been saved\n")

'''
# In google colab 
------------------------------------------
import requests

image_url = "https://example.com/file.png" # Paste file url here

r = requests.get(image_url)

print("\nDownloading Files...\n")

# Enter your file name ⬇⬇
with open("exampleFile.png", "wb") as foo:
    foo.write(r.content)
    print("\nFile has been saved\n")

'''

Enter fullscreen mode Exit fullscreen mode

Writer ⮕ Junaid

Publisher ⮕ Junaid

Top comments (0)