この質問はBeautifulSoup4に固有のものであり、前の質問とは異なります。
BeautifulSoupが自己閉鎖要素を変更するのはなぜですか?
なくなったので(以前のxmlパーサー)、新しい自己終了タグを尊重するBeautifulStoneSoup
にはどうすればよいですか?bs4
例えば:
import bs4
S = '''<foo> <bar a="3"/> </foo>'''
soup = bs4.BeautifulSoup(S, selfClosingTags=['bar'])
print soup.prettify()
タグをセルフクローズしませんbar
が、ヒントを提供します。bs4が参照しているこのツリービルダーとは何ですか?タグをセルフクローズする方法は?
/usr/local/lib/python2.7/dist-packages/bs4/__init__.py:112: UserWarning: BS4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.
"BS4 does not respect the selfClosingTags argument to the "
<html>
<body>
<foo>
<bar a="3">
</bar>
</foo>
</body>
</html>