python 中文和html 实体相互转换

在爬有些网页的中文经常以html 实体出现。

python & #20013;& #25991;& #21644;html & #23454;& #20307;& #30456;& #20114;& #36716;& #25442;

把html 实体和中文互转:

import res = 'python 中文和html 实体相互转换'# s = 'python & #20013;& #25991;& #21644;html & #23454;& #20307;& #30456;& #20114;& #36716;& #25442;'print sdef convert_callback(matches):    char_id = matches.group(1)    try:        return unichr(int(char_id))    except:        return char_ids2 = re.sub("<!

python 中文和html 实体相互转换

相关文章:

你感兴趣的文章:

标签云: