使用来自 python 2.7.6 的 bs4 解析此示例文档:
<html>
<body>
<p>HTML allows omitting P end-tags.
<p>Like that and this.
<p>And this, too.
<p>What happened?</p>
<p>And can we <p>nest a paragraph, too?</p></p>
</body>
</html>
使用:
from bs4 import BeautifulSoup as BS
...
tree = BS(fh)
多年来,HTML 允许省略各种元素类型的结束标记,包括 P(检查架构或解析器)。但是,bs4 在此文档中的 prettify() 显示它在看到