Comment intégrer balise p à l'intérieur du texte en utilisant beautifulsoup?

StackOverflow https://stackoverflow.com/questions/527629

  •  22-08-2019
  •  | 
  •  

Question

Je voulais intégrer <p> balise où jamais il y a un \ r \ n \ r \ n.

u "Enfin Sri Lanka se sont présentés, ont empêché leur première badigeon série 5-0, et arrêté l'Inde à neuf ODI victoires d'affilée. \ R \ n \ r \ nPour 62 boules Yuvraj Singh a joué un rêve frapper, en gardant l'Inde dans le jeu malgré portillons tomber autour de lui. \ r \ n \ r \ nPerhaps le toss a joué un grand rôle. Ce fut la deuxième fois Mahela Jayawardene a battu Mahendra Singh Dhoni avec la pièce de monnaie au cours des 11 dernières occasions. \ r \ n \ r \ nIl était Jayasuriya qui a fourni au Sri Lanka avec le tremplin. \ r \ n \ r \ nLes la pyrotechnie peut-être arrêté sur le licenciement de Jayasuriya, mais les courses continué à venir à un bon rythme. "

J'ai essayé de résoudre ce en utilisant BeautifulSoup mais n'a pas pu trouver le moyen d'en sortir. Quelqu'un peut-il par un peu de lumière à ce sujet. Merci à l'avance.

Était-ce utile?

La solution

''.join('<p>%s</p>' % line for line in text.split('\r\n\r\n'))
# Results:
u"<p>Finally Sri Lanka showed up, prevented their first 5-0
series whitewash, and stopped India at nine ODI wins in a row. </p>
<p>For 62 balls Yuvraj Singh played a dream knock, keeping India in the 
game despite wickets falling around him. </p><p>Perhaps the toss played
a big part. This was only the second time Mahela Jayawardene beat Mahendra
Singh Dhoni with the coin in the last 11 occasions. </p>
<p>It was Jayasuriya who provided Sri Lanka with the springboard. </p>
<p>The pyrotechnics may have stopped upon Jayasuriya's dismissal, but 
the runs kept coming at a fair pace.</p>"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top