<div id="div_1">
<p class="keywords">
<strong> Those are the main keywords </strong>
<ol>
<li>Decentralization</li>
<li>Planning</li>
</ol>
</p>
</div>
<div id="div_2">
<p class="keywords">
<strong>This is the first paragraph of the second div </strong>
<strong>This is the second paragraph of the second div </strong>
</p>
</div>
<div id="div_3">
<p> This is the first paragraph of the second div </p>
</div>
Я хочу проанализировать этот файл html, чтобы у меня был каждый div в строке, что означает следующий вывод:
Those are the main keywords Decentralization Planning
This is the first paragraph of the second div This is the second paragraph of the second div
This is the first paragraph of the third div
Это мой код:
soup = BeautifulSoup (open(document, encoding = "utf8"), "html.parser")
myDivs = soup.findAll("div", id = re.compile("^div_"))
for div in myDivs:
txt = div.text + "\n"
print (txt)
Это возвращает мне текст
, но с каждым из его тегов (
, ) в строке
Есть идеи, как мне это сделать?