0
このようにHTMLからテキストタグを削除し、子要素を残す方法を教えてください。美味しいスープで「テキストタグ」を削除するには
<p>sample text</p>
<image>
<figure>
<img alt="" src="xxxxx.jpg"/>
</figure>
</image>
を次のように私はそれを変換したい
<text _ngcontent-c0="" _nghost-c2="">
<p>sample text</p>
</text>
<image>
<figure>
<img alt="" src="xxxxx.jpg"/>
</figure>
</image>
私は、次の方法を試してみましたが、エラー'str' object has no attribute 'unwrap'
が発生しました。あなたはこのような「開封された」要素を取得することができます
from bs4 import BeautifulSoup
content = '<text _ngcontent-c0="" _nghost-c2="">
<p>sample text</p>
</text>
<image>
<figure>
<img alt="" src="xxxxx.jpg"/>
</figure>
</image>'
while (content.text):
content.text.unwrap()
説明が不明なため申し訳ありません。 コンテンツに他の要素がある場合に対応する方法を知りたい。 私の質問が更新されました。 – xKxAxKx
私の例は、あなたの更新されたケースでもうまくいくはずです。 '
サンプルテキスト