网上找了太多了。什么比如iconv-lite什么的,都试过了。就是不行。
href = 'http://www.qq.com/';
console.log(href);
superagent.get(href).end(function (err, res) {
var str = res.text;
var buf = new Buffer(str);
str = iconv.decode(buf, 'GBK');
console.log(str);
});
折腾了一夜了,可有解决方案?
http://web-engineer.cn/article/29
Use superagent-charset module
I just took the time to modify this module, https://github.com/52cik/superagent-charset
I don’t know when the author will merge my code,
you can directly
npm i 52cik/superagent-charset
install and use it .How to use:
Not superagent, use the http module provided by nodejs
The final file content after decoding is UTF-8
new Buffer(string[,encoding])
itself will have a transcoding process, the default is UTF-8, that is to say,is as follows,
encodes first, then toString, then new Buffer, and finally decodes with GBK to get There is a problem with the result
Post an example of using native: