在使用 NodeJs 采集其他网站网页时遇到的,在获取源代码后发现里面原来的中文被转成了 Unicode(UTF8) 编码的中文(如:&# [xxx]),这当然不是真正想要的中文实体

解决方案:

使用 html-entities 对字符进行解码

安装:

npm install --save html-entities

使用:

var Entities = require('html-entities').XmlEntities;
entities = new Entities();
var str = '<p>&# [xxx]</p>';

console.log(entities.decode(str));

 

相关文章:

  • 2021-12-23
  • 2021-10-13
  • 2021-12-16
  • 2022-12-23
  • 2021-12-03
  • 2021-12-05
  • 2021-10-29
  • 2021-12-07
猜你喜欢
  • 2021-12-11
  • 2021-11-23
  • 2021-10-19
  • 2022-12-23
  • 2021-05-03
相关资源
相似解决方案