How to get BeautifulSoup 4 to respect a self-closing tag?(如何让 BeautifulSoup 4 尊重自闭标签?)
问题描述
这个问题是针对 BeautifulSoup4 的问题,这使得它不同于以前的问题:
This question is specific to BeautifulSoup4, which makes it different from the previous questions:
BeautifulSoup 为什么要修改我的自闭合元素?
BeautifulSoup 中的 selfClosingTags
由于 BeautifulStoneSoup
已经消失(之前的 xml 解析器),我怎样才能让 bs4
尊重一个新的自闭合标签?例如:
Since BeautifulStoneSoup
is gone (the previous xml parser), how can I get bs4
to respect a new self-closing tag? For example:
不会自动关闭 bar
标签,但会给出提示.bs4 所指的这个树生成器是什么以及如何自我关闭标签?
Does not self-close the bar
tag, but gives a hint. What is this tree builder that bs4 is referring to and how to I self-close the tag?
推荐答案
解析你传入的XMLxml"作为 BeautifulSoup 构造函数的第二个参数.
您需要安装 lxml.
您不再需要传递 selfClosingTags
:
这篇关于如何让 BeautifulSoup 4 尊重自闭标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!