Cheerio: .html() act strange with non-ANCII characters

Created on 24 Feb 2017  路  2Comments  路  Source: cheeriojs/cheerio

const $ = require('cheerio');
$('<p>涓枃娴嬭瘯</p>').html()

Will get something like this: '&#x4E2D;&#x6587;&#x6D4B;&#x8BD5;', correct result should be '<p>涓枃娴嬭瘯</p>'.

Most helpful comment

@muyinliu doing it this way decodes the HTML entities into the actual characters:

const cheerio = require('cheerio');
const $ = cheerio.load('<p>涓枃娴嬭瘯</p>', {
  decodeEntities: false
});
console.log($.html()); // <p>涓枃娴嬭瘯</p>

All 2 comments

@muyinliu doing it this way decodes the HTML entities into the actual characters:

const cheerio = require('cheerio');
const $ = cheerio.load('<p>涓枃娴嬭瘯</p>', {
  decodeEntities: false
});
console.log($.html()); // <p>涓枃娴嬭瘯</p>

Thanks. It works fine now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlbertoElias picture AlbertoElias  路  4Comments

clayrisser picture clayrisser  路  4Comments

miguelmota picture miguelmota  路  3Comments

unicrus picture unicrus  路  4Comments

robogeek picture robogeek  路  4Comments