在爬有些网页的中文经常以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 实体相互转换, 感谢原作者分享。 我想去旅行,一个人背包,一个人旅行,