Cheerio: How can I convert the .html() to normal text?

Created on 7 Oct 2015  路  5Comments  路  Source: cheeriojs/cheerio

Cheerio only provides $.html() to get the html string. However, all the unicode is converted like 你可能感兴趣. I want to convert these encoded html to normal text like 浣犲彲鑳芥劅鍏磋叮.

How can I do it in Node.js?

Most helpful comment

$ = cheerio.load('<ul id="fruits">浣犲彲鑳芥劅鍏磋叮</ul>', {
    decodeEntities: false
});

All 5 comments

$ = cheerio.load('<ul id="fruits">浣犲彲鑳芥劅鍏磋叮</ul>', {
    decodeEntities: false
});

@alanev So if I already have a string of &#x4F60;&#x53EF;&#x80FD;&#x611F;&#x5174;&#x8DA3;, how can I get the original text?

I find a library to convert the html entity to unicode text.

https://github.com/substack/node-ent

Good job!

Cool. But what is decodeEntities used for. If set it to false, it will cause parsing slower?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

M3kH picture M3kH  路  4Comments

dandv picture dandv  路  5Comments

tndev picture tndev  路  4Comments

kminehart picture kminehart  路  5Comments

gajus picture gajus  路  4Comments