JustCaptain kod-buduschego
llm/change-52ed52
Перейти к файлу
Код
kod-buduschego Python 2025-20264.2. Веб-скрапингpracticestask_2.py
anc update c70a58f 8 октября 2026 г.
task_2.py
import requests
from bs4 import BeautifulSoup

url: str = "https://new-science.ru/category/news/page/2/"
response = requests.get(url)

# /// Через BeautifulSoup решение
soup = BeautifulSoup(response.text, "html.parser")
print(soup.title)

# /// Альтернативное решение
title_start_index = response.text.find("<title>")
title_end_index = response.text.find("</title>")
print(f"Старт: {title_start_index}\nКонец: {title_end_index}")
print(f"{response.text[title_start_index:title_end_index]}")



with open("site.html", mode="w", encoding="utf-8") as file:
    file.write(response.text)