How to replace/convert/correct a string representing tag into a tag?
I have below example where I need to clean some parts of the code and need to convert strings like </div> into the proper tags
html = """
<html>
<body>
<div>
</div> <----- how to convert the line into </div>
<div class="first_class">
<h1 id="Header_1">
Header_1
</h1>
</div>
</body>
</html>
"""
I tried
soup = BeautifulSoup(html,"lxml")
tag = soup.find(text="<")
tag.replace_with("<")
print(soup.prettify())
but this logic doesn't work, the find function doesn't pick up the string. The fact that the text is outside of any tag makes it more difficult. How can this be achieved?