# -*- coding: utf-8 -*- import re from lxml.html import fromstring, HtmlElement, tostring __all__ = ['cleaner', 'drop_tree_by_lxml'] '''独立元素''' INDEPENDENT_TAGS = { '[\s\S]*?': '', '|]*>|': '', '|]*>|': '', ']*>|]*>|]*>[\s\S]*?|': '', # 元数据 '&(nbsp|e[mn]sp|thinsp|zwn?j|#13);': '', # 空格 '\\xa0|\\u3000': '', # 空格 '': '', # 注释 ']*>[\s\S]*?': '', # 样式 ']*>[\s\S]*?': '', # JavaScript '': '', # 输入框 '': '', # 输入框 ']*>': '
', # 图片 } '''行内元素''' INLINE_TAGS = { '|]*>|': '', # 超链接 '|]*>|': '', # 超链接 '|]*>|': '', # span '