Last active
April 8, 2022 11:25
-
-
Save pointofpresence/889dd22522e558241def4208ed0e1d52 to your computer and use it in GitHub Desktop.
Python Yandex Disk Download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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