使用 cheerio 有没有出现过乱码的情况
发布于 10 年前 作者 surgit 13525 次浏览 最后一次编辑是 8 年前

https://github.com/MatthewMueller/cheerio

有没有出现过中文乱码的。

 <meta name="keywords" content="&#x4E50;&#x8DA3;&#xFF01;!">

我自己用的时候会出现 一些中文 转为unicode

5 回复

主要是title 和 alt属性这些 会编程 unicode 编码,,求助。

var $ = cheerio.load(htmlStr, {decodeEntities: false});

先转码吧。

true-html-escape 不谢:https://www.npmjs.com/package/true-html-escape

var escaper = require("true-html-escape");
 
escaper.escape("¤¥€");                                                  ///<= &curren;&yen;&euro; 
escaper.unescape("&lt;span&gt;&#29579;&#23612;&#29595;&lt;/span&gt;");  ///<= <span>王尼玛</span> 
escaper.unescape("&#12501;&#12521;&#12531;&#12489;&#12540;&#12523;");   ///<= フランドール 
escaper.unescape("(&#x256d;&#xffe3;3&#xffe3;)&#x256d;&#x2661;")         ///<= (╭ ̄3 ̄)╭♡ 

cheerio = Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

有点意思

回到顶部