first commit

This commit is contained in:
2026-09-11 16:37:55 +03:00
commit 4dd137dc09
2 changed files with 111 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import os
import requests
from urllib.parse import unquote, urlparse
# Список URL для скачивания
URL_LIST = [
"https://example.com/sample.pdf",
"https://example.com/image.png",
]
# Папка для сохранения
SAVE_DIR = "/dw"
def download_files(urls, destination_folder):
# Создаем папку, если она не существует
os.makedirs(destination_folder, exist_ok=True)
for url in urls:
# Извлекаем имя файла из URL
parsed_url = urlparse(url)
filename = os.path.basename(unquote(parsed_url.path)) or "downloaded_file"
save_path = os.path.join(destination_folder, filename)
try:
response = requests.get(url, stream=True, timeout=15)
response.raise_for_status()
with open(save_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Сохранен: {save_path}")
except Exception as e:
print(f"Ошибка при скачивании {url}: {e}")
if __name__ == "__main__":
download_files(URL_LIST, SAVE_DIR)