BeautifulSoup을 사용하여 일부 텍스트 안에 P 태그를 포함시키는 방법은 무엇입니까?
-
22-08-2019 - |
문제
나는 포함하고 싶었다 <p
> r n r n이있는 곳에 태그가 있습니다.
U "마침내 스리랑카가 나타나서 첫 5-0 시리즈 화이트 워시를 막았으며 9 번의 ODI 승리로 인도를 중단했습니다. 개찰구가 그 주위에 떨어지지 않더라도. r n r nperhaps 토스는 큰 역할을했습니다. 이것은 지난 11 번의 Mahela Jayawardene이 Mahendra Singh Dhoni를 비트로 두 번째로 만들었습니다. r n n r nit. 스리랑카에게 발판을 제공 한 Jayasuriya였습니다. r n r n Pyrotechnics는 Jayasuriya의 해고를 중단했을지 모르지만, 런은 계속해서 공정한 속도로 왔습니다. "
BeautifulSoup을 사용하여 이것을 해결하려고 시도했지만 그 길을 찾을 수 없었습니다. 이것에 대한 빛을 통해 누구든지 할 수 있습니다. 미리 감사드립니다.
해결책
''.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>"
제휴하지 않습니다 StackOverflow