A
A
alekssamos2021-10-22 17:47:28
Parsing
alekssamos, 2021-10-22 17:47:28

Bring FB2 code back to normal?

There is an XML code for a non-standard FB2 file: (1)

<section>
    <p>Глава первая.</p>
</section>
<p>Текст первой главы.</p>
<section>
    <p>Глава вторая.</p>
</section>
<p>Текст второй главы.</p>

And it should be like this: (2)

<section>
    <p>Глава первая.</p>
    <p>Текст первой главы.</p>
</section>
<section>
    <p>Глава вторая.</p>
    <p>Текст второй главы.</p>
</section>


I use
from bs4 import BeautifulSoup
bs=BeautifulSoup(xml_code)
for chapter in bs.find_all("section"): chapter.text

How to make from (1) (2) ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question