File: //workspace/parse_lehrplan.py
from bs4 import BeautifulSoup
import re
def extract_content(filename):
with open(filename, 'r', encoding='utf-8') as f:
html = f.read()
soup = BeautifulSoup(html, 'html.parser')
# Finde den Hauptcontent-Bereich
content = soup.find('div', {'id': 'content'})
if not content:
return "Kein Content gefunden"
# Extrahiere Text mit Struktur
text_parts = []
# Finde alle Lernbereiche
for section in content.find_all(['h4', 'h5', 'p', 'li'], recursive=True):
if section.name in ['h4', 'h5']:
text_parts.append(f"\n=== {section.get_text(strip=True)} ===")
elif section.name == 'p':
text = section.get_text(strip=True)
if text and not text.startswith('Die Schülerinnen und Schüler ...'):
text_parts.append(text)
elif section.name == 'li':
text = section.get_text(strip=True)
# Entferne Prozessbezogene Kompetenzen-Texte
text = re.sub(r'Prozessbezogene Kompetenzen:.*$', '', text, flags=re.MULTILINE)
if text:
text_parts.append(f"- {text}")
return '\n'.join(text_parts)
alt = extract_content('/workspace/lehrplan_alt.html')
neu = extract_content('/workspace/lehrplan_neu.html')
with open('/workspace/lehrplan_alt_text.txt', 'w', encoding='utf-8') as f:
f.write(alt)
with open('/workspace/lehrplan_neu_text.txt', 'w', encoding='utf-8') as f:
f.write(neu)
print("Extraktion abgeschlossen")
print(f"Alt: {len(alt)} Zeichen")
print(f"Neu: {len(neu)} Zeichen")