Python 过滤HTML实体符号简易方法

html_tag = {'&#xA;': '\n', '&quot;': '\"', '&amp;': '', '&lt;': '<', '&gt;': '>',
'&apos;': "'", '&nbsp;': ' ', '&yen;': '¥', '&copy;': '©', '&divide;': '÷'
, '&times;': 'x', '&trade;': '™', '&reg;': '®', '&sect;': '§', '&euro;': '€',
'&pound;': '£', '&cent;': '¢', '&raquo;': '»'
}

for k, v in html_tag.items():
  str = str.replace(k, v)
  str = str.replace(k[1:], v)

# str就是要过滤的字符串
posted @ 2019-08-16 13:54  liuxianglong  阅读(435)  评论(0编辑  收藏  举报