79250388

Date: 2024-12-04 08:41:56
Score: 1
Natty:
Report link

Recall that <br> is used inside <p>, so here is a string hack.

html = html.replace("<br>", "</p><p>")
soup = BeautifulSoup(html, "html.parser")
soup.find_all('p')

Note that this is not an "open and closing paragraph" tag but rather "closing then opening".

<p>
 part1
 </p><p>
 part2
 </p><p>
 part3
 </p><p>
 part4
</p>

Now all p tags match each other, though a bit messy with line breaks, which can be fixed by soup.prettify().

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: congtailai