最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】Python中将HTML实体 解码后,输出到cmd中却显示异常

Python crifan 2634浏览 0评论

折腾一个python脚本期间,涉及到,

将一个html实体:

 

解码:

            itemInfoDict['labelNumber'] = crifanLib.decodeHtmlEntity(itemInfoDict['labelNumber']);
            itemInfoDict['districtCounty'] = crifanLib.decodeHtmlEntity(itemInfoDict['districtCounty']);
            itemInfoDict['signage'] = crifanLib.decodeHtmlEntity(itemInfoDict['signage']);
            itemInfoDict['companyName'] = crifanLib.decodeHtmlEntity(itemInfoDict['companyName']);
            itemInfoDict['licenseNumber'] = crifanLib.decodeHtmlEntity(itemInfoDict['licenseNumber']);
            itemInfoDict['currentLevel'] = crifanLib.decodeHtmlEntity(itemInfoDict['currentLevel']);

后,用对应的python代码:

            logging.info(u"=============== 序号:%s ===============", itemInfoDict['labelNumber']);
            logging.info(u"区县     =%s", itemInfoDict['districtCounty']);
            logging.info(u"店招     =%s", itemInfoDict['signage']);
            logging.info(u"单位名称 =%s", itemInfoDict['companyName']);
            logging.info(u"许可证号 =%s", itemInfoDict['licenseNumber']);
            logging.info(u"当前等级 =%s", itemInfoDict['currentLevel']);

输出到windows的cmd中,结果显示异常:

LINE 136  : INFO     =============== 序号:3 ===============
LINE 137  : INFO     区县     =长宁
LINE 138  : INFO     搴楁嫑     =聽
LINE 139  : INFO     单位名称 =上海四建服务中心樱花度假村
LINE 140  : INFO     许可证号 =(沪长)食临证字[2006]第070010号
LINE 141  : INFO     当前等级 =良好

相对的,在log文件中的正常的输出是:

LINE 136   INFO     =============== 序号:3 ===============
LINE 137   INFO     区县     =长宁
LINE 138   INFO     店招     =  LINE 139   INFO     单位名称 =上海四建服务中心樱花度假村
LINE 140   INFO     许可证号 =(沪长)食临证字[2006]第070010号
LINE 141   INFO     当前等级 =良好

此处,觉得很奇怪。对于cmd中无法正常输出 觉得很奇怪

目前的推测是:

windows的cmd中,不支持 这个相对特殊的字符的显示。

而对于不支持,不知道是cmd本身不支持,还是由于本身cmd所用的GBK编码中,就不支持。

而导致此处,显示 时,变成了:

要显示出来的一行字符串,本身就变成乱码字符;

而且还出现错位的现象。

转载请注明:在路上 » 【记录】Python中将HTML实体 解码后,输出到cmd中却显示异常

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
81 queries in 0.164 seconds, using 22.01MB memory