安装
pip install lxml
代码示例
from lxml import etree
text = """
这是标题
这是内容
"""
html = etree.HTML(text)
# 使用xpath解析
titles = html.xpath("//title")
for title in titles:
print(title.text)
# 使用css解析
titles = html.cssselect("title")
for title in titles:
print(title.text)