解析库 解析器 使用方法 优势 劣势 Python标准库 BeautifulSoup(markup, "html.parser") Python的内置标准库、执行速度适中 、文档容错能力强 Python 解析器 BeautifulSoup(markup, "xml") 速度快、唯一支持XML的解析器 需要安装C语言库 html5lib BeautifulSoup(markup, "html5lib") names were <span >Elsie</span> <a href="http://example.com/lacie" class="sister" id="link2 </p> """ from bs4 import BeautifulSoup soup = BeautifulSoup(html, 'lxml') print(soup.prettify()) print
names were <span >Elsie</span> <a href="http://example.com/lacie" class="sister" id="link2 >Elsie</<em>span</em>> </a> <a href="http://example.com/lacie" class="sister" id="link2 >Elsie</<em>span</em>> </a> <a href="http://example.com/lacie" class="sister" id="link2 >Elsie</<em>span</em>> </a> <a href="http://example.com/lacie" class="sister" id="link2