Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active April 8, 2022 11:25
Show Gist options
  • Save pointofpresence/889dd22522e558241def4208ed0e1d52 to your computer and use it in GitHub Desktop.
Save pointofpresence/889dd22522e558241def4208ed0e1d52 to your computer and use it in GitHub Desktop.
Python Yandex Disk Download
import requests
from urllib.parse import urlencode
base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?'
public_key = 'https://yadi.sk/d/UJ8VMK2Y6bJH7A' # Сюда вписываете вашу ссылку
# Получаем загрузочную ссылку
final_url = base_url + urlencode(dict(public_key=public_key))
response = requests.get(final_url)
download_url = response.json()['href']
# Загружаем файл и сохраняем его
download_response = requests.get(download_url)
with open('downloaded_file.txt', 'wb') as f: # Здесь укажите нужный путь к файлу
f.write(download_response.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment