Bakalarska_praca/data_files/convert_html.py
2024-10-23 13:43:55 +02:00

19 lines
588 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from bs4 import BeautifulSoup
# Открываем HTML файл
with open('file.html', 'r', encoding='windows-1250') as file:
html_content = file.read()
# Парсим HTML с BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
# Извлекаем текст, удаляя все HTML-теги
text = soup.get_text()
# Записываем текст в файл (или делаем с ним что-то другое)
with open('output.txt', 'w', encoding='utf-8') as output_file:
output_file.write(text)
print("Текст успешно извлечён!")