HTML Parser от More Exercises: Regular Expressions
Здравейте,
Имам проблем, а по успелите на тази задача (само 1 човек), виждам, че не само аз съм така със задачата на този линк:
https://judge.softuni.bg/Contests/Practice/Index/1744#4
По-долу е моето решение, но не минава 1-ви и 3ти тест. Опитах се да добавя какви ли не проверки, но нищо не се променя. Затова разчитам на помощ от колеги.
Предварително благодаря!
import re
html_line = input()
title_pattern = '(?<=title>).+(?=</title)'
body_pattern = '(?<=body>).+(?=</body)'
title = re.findall(title_pattern, html_line)
y = re.findall(body_pattern, html_line)
body_split_pattern = '[<].+?[>]'
z = re.split(body_split_pattern, *y)
content = ""
for s in z:
if s != '' and not s.isdigit(): # removing the digits and the empty strings lefts from tags placed one after the other
if '\\n' in s:
s = " ".join(re.split(r'\\n', s)) # removing the '\n' in the content
content += s.strip() + " "
print("Title:", "".join(title))
print("Content:", content.strip()) # .strip() to remove the last " "