superagent抓取gb2312网页出来是十六进制的解决办法

var htmlentities = {
    encode: function(str) {
            var buf = [];
            
            for (var i=str.length-1;i>=0;i--) {
                buf.unshift(['&#', str[i].charCodeAt(), ';'].join(''));
            }
            
            return buf.join('');
        },
    decode: function(str) {
            return str.replace(/&#(\d+);/g, function(match, dec) {
                return String.fromCharCode(dec);
            });
        }
}

 

posted @ 2017-06-28 22:09  white_0710  阅读(304)  评论(0编辑  收藏  举报