If you’re dealing with super messy HTML, try `bleach` + BeautifulSoup. Bleach cleans the HTML first, then BS4 extracts text.
```python
import bleach
from bs4 import BeautifulSoup
clean = bleach.clean(open("file.html").read())
soup = BeautifulSoup(clean, "html.parser")
print(soup.get_text())
```
Extra step, but worth it for nasty files when you need python clean html into text file reliably.
```python
import bleach
from bs4 import BeautifulSoup
clean = bleach.clean(open("file.html").read())
soup = BeautifulSoup(clean, "html.parser")
print(soup.get_text())
```
Extra step, but worth it for nasty files when you need python clean html into text file reliably.
