删除python中的所有html? [英] Remove all html in python?
本文介绍了删除python中的所有html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以使用lxml.html而不是有一些xss问题的beautifulsoup来删除/转义html标签?我尝试使用清洁器,但我想删除所有html.
Is there a way to remove/escape html tags using lxml.html and not beautifulsoup which has some xss issues? I tried using cleaner, but i want to remove all html.
推荐答案
请尝试在元素上使用.text_content()
方法,最好是在使用lxml.html.clean
清除不需要的内容(脚本标记等)之后.例如:
Try the .text_content()
method on an element, probably best after using lxml.html.clean
to get rid of unwanted content (script tags etc...). For example:
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文