Dom*_*ger 3 python django html5lib
我一直在使用优秀的漂白库来删除错误的HTML.
我有一堆HTML文档已经从Microsoft Word粘贴,包含以下内容:
<STYLE> st1:*{behavior:url(#ieooui) } </STYLE>
Run Code Online (Sandbox Code Playgroud)
使用漂白(style隐藏不允许标记),让我:
st1:*{behavior:url(#ieooui) }
Run Code Online (Sandbox Code Playgroud)
哪个没用.Bleach似乎只有以下选项:
我正在寻找第三种选择 - 删除标签及其内容.
事实证明这lxml是一个更好的工具来完成这项任务:
from lxml.html.clean import Cleaner
def clean_word_text(text):
# The only thing I need Cleaner for is to clear out the contents of
# <style>...</style> tags
cleaner = Cleaner(style=True)
return cleaner.clean_html(text)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1103 次 |
| 最近记录: |