I'm trying to extract some text using BeautifulSoup
. I'm using get_text()
function for this purpose.
My problem is that the text contains </br>
tags and I need to convert them to end lines. how can I do this?
The RegEx is used with the replace() method to replace all the line breaks in string with <br>. The pattern /(\r\n|\r|\n)/ checks for line breaks. The pattern /g checks across all the string occurrences.
Use <br> tags to force line breaks on screen.
The \n character matches newline characters.
The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.
You can do this using the BeautifulSoup object itself, or any element of it:
for br in soup.find_all("br"): br.replace_with("\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With