节点js NPM cheerio变成“进入”

时间:2015-08-21 15:09:46

标签: html json node.js quotes cheerio

我的应用程序正在请求服务器并返回html。

当html回来时,我正在通过cheerio运行它并修改html中找到的域名。

当返回字符串化的Json时,cheerio正在替换“with& quot”,这导致它无法被javascript解析。

HTML中的“s”不会被cheerio更改为“&amp; quot。有人可以告诉我为什么它会改变字符串化的Json而不是HTML并且还告诉我如何阻止它改为&amp; quot < / p>

我的HTML的Cheerios输出

<div id="et-info">
    <span id="et-info-phone">+44 0000 000000</span>
     <a href="mailto:hello@newdomain.com"><span id="et-info-email">hello@newdomain.com</span></a>
</div>

未解析的Json字符串的Cheerios输出

{&quotresult&quot:&quotsuccess&quot,&quotredirect&quot:&quothttp:\/\/www.domain.com\/checkout\/order-pay\/3798?key=wc_order_55d7344aa233b&quot}

我已经尝试添加

decodeEntities:true

var $ = cheerio.load(html[key], { decodeEntities: true });

1 个答案:

答案 0 :(得分:1)

将decodeEntities设置为false将修复正在发生的事情。

var $ = cheerio.load(html[key], { decodeEntities: false});