PYTHON 提取HTML文本

from lxml.html import etree

content = "***************"
html = etree.HTML(str(content))
html_data = html.xpath('//span/text()|//p//text()|//section//text()')
datas = [data.replace("\r", "").replace("\n", '').replace('\t', '').replace('\xa0', '') for data in list(html_data)]
ori_content = ' '.join([d for d in datas if d])

 

posted @ 2022-08-05 15:23  cup_leo  阅读(626)  评论(0编辑  收藏  举报