Скачать файл с помощью Python

Подготовка

Активируйте ваше виртуальное окружение и установите requests командой

python3 -m pip install requests

Изучите список установленных модулей

python3 -m pip list

Package Version ---------- --------- certifi 2020.6.20 chardet 3.0.4 idna 2.10 pip 20.2.3 requests 2.24.0 setuptools 50.3.1 urllib3 1.25.10 wheel 0.35.1

requests подтягивает за собой requests, certifi, chardet, idna, urllib3

Проверить куда установился requests в этом окружении можно командой

python3 -m pip show requests

Name: requests Version: 2.24.0 Summary: Python HTTP for Humans. Home-page: https://requests.readthedocs.io Author: Kenneth Reitz Author-email: me@kennethreitz.org License: Apache 2.0 Location: /home/andrei/python/virtualenvs/answerit_env/lib/python3.8/site-packages Requires: certifi, chardet, urllib3, idna Required-by:

Создайте файл download_demo.py

import requests url = 'http://some_url' r = requests.get(url) with open('file_name', 'wb') as f: f.write(r.content)

Запустите скрипт командой

python3 download_demo.py

Должен появиться файл с нужным контентом

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: