.text_content()
在元素上尝试该方法,可能是最好的方法,用于lxml.html.clean
去除不需要的内容(脚本标签等)。例如:
from lxml import html
from lxml.html.clean import clean_html
tree = html.parse('http://www.example.com')
tree = clean_html(tree)
text = tree.getroot().text_content()
删除python中的所有html?
.text_content()
在元素上尝试该方法,可能是最好的方法,用于lxml.html.clean
去除不需要的内容(脚本标签等)。例如:
from lxml import html
from lxml.html.clean import clean_html
tree = html.parse('http://www.example.com')
tree = clean_html(tree)
text = tree.getroot().text_content()