采集某网页需要的一段python编码,解决html代码转换问题,搞了一个下午,原来又是个好简单的问题
def unescape_word(s):
words = re.findall(“&#(\d+);”, s)
if words:
result=s
for r in words:
word =unichr(int(r))
result = result.replace(“&#%s;” % r,word)
else:
result = s
return result
这样使用:
m1=’ACA 面包机MB-600(黄色)’
print unescape_word(m1)