python用lxml提取html标签中的内容

[python] 2024-05-07 圈点526

摘要:python用lxml提取html标签中的内容,直接上示例代码:python用lxml模块也是可以解析html代码,并提取html中的数据内容的。

python用lxml提取html标签中的内容,直接上示例代码:python用lxml模块也是可以解析html代码,并提取html中的数据内容的。


from lxml import etree
content = "<html><div><p class='test'></p></div></html>"
tree=etree.HTML(content)
node=tree.xpath("//p[@class='test']")[0]
print node.text
print node.text.encoding('gbk')


python用lxml模块也是可以解析html代码,并提取html中的数据内容的。

python  lxml  html  

感谢反馈,已提交成功,审核后即会显示