Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert </br> to end line

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?

like image 417
MBZ Avatar asked Sep 22 '12 17:09

MBZ


People also ask

How do I replace all line breaks in a string with br /> elements?

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.

What is br /> in XML?

Use <br> tags to force line breaks on screen.

What is \n HTML?

The \n character matches newline characters.

How do you break a line in HTML?

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.


1 Answers

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") 
like image 58
Ian Mackinnon Avatar answered Oct 12 '22 05:10

Ian Mackinnon