Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Download_file_from_url.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Download file from url

Give Feedback | Bug report

Tags: #github #productivity #code #operations #snippet #dataframe

Last update: 2023-04-24 (Created: 2022-03-18)

Description: This notebook provides instructions on how to download a file from a URL using GitHub.

Input

Import needed library

import requests import naas import uuid

Model

Default Github file for testing purpose

target = "https://github.com/jupyter-naas/awesome-notebooks/blob/master/Plotly/Create%20Candlestick%20chart.ipynb"

Convert url to downloadable one

# https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Dataviz/Plotly/Create%20Candlestick%20chart.ipynb raw_target = target.replace("https://github.com/", "https://raw.githubusercontent.com/") raw_target = raw_target.replace("/blob/", "/") print(raw_target)

Output

Dowload file locally

import urllib.parse r = requests.get(raw_target) uid = uuid.uuid4().hex file_name = raw_target.split("/")[-1] file_name = urllib.parse.unquote(file_name) with open(file_name, "wb") as f: f.write(r.content)