/
rnekrasov
/
Python
Обзор
Документация
Войти
/
rnekrasov
/
Python
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
scrap_file.py
38 строк
966 B
slowy07
refactor: clean code
30 янв 2022, 04:33
30 янв 2022, 04:33
f0af0c4
Код
Авторство
О чём код?
# Author : RIZWAN AHMAD # pip3 install requests import requests # Function for download file parameter taking as url def download(url): f = open( "file_name.jpg", "wb" ) # opening file in write binary('wb') mode with file_name.ext ext=extension f.write(requests.get(url).content) # Writing File Content in file_name.jpg f.close() print("Succesfully Downloaded") # Function is do same thing as method(download) do,but more strict def download_2(url): try: response = requests.get(url) except Exception: print("Failed Download!") else: if response.status_code == 200: with open("file_name.jpg", "wb") as f: f.write(requests.get(url).content) print("Succesfully Downloaded") else: print("Failed Download!") url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4" # URL from which we want to download download(url)