采集下来的网页,有时有一些html实体,有库可以直接替换掉


通常用的是HTMLParser库或者lxml库


直接贴代码

#coding=utf-8

test_string=u"环球老虎财经: 交通银行(601328.SH)混合所有制"起底" "

import HTMLParser
print HTMLParser.HTMLParser().unescape(test_string)

import lxml.html
x=lxml.html.fromstring(test_string)
print x.text_content()


注意一点的,传入的字符串都要求unicode字符串


update:

上面的lxml中text_content()返回的无标签网页文本,使用会有局限性,所以还是推荐用HTMLParser库