DEV Community

Junaid
Junaid

Posted on

3 3

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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more