node.js通过iconv-lite完成gbk字符解码例子
通过 iconv-lite可以实现中文字符解码
1.安装iconv-lite
npm install iconv-lite
2.iconv-lite网址如下
iconv-lite
https://github.com/ashtuchkin/iconv-lite
3.使用iconv-lite例子代码如下
let http = require("https");
let iconv = require("iconv-lite");
let url="https://www.2717.com/ent/meinvtupian/"
http.get(url,res=>{
let data =[];
res.on("data",chunk =>{
data.push(chunk)
} );
res.on("end",()=>{
// console.log("下载完成");
let html='';
html= iconv.decode(Buffer.concat(data),"gbk");
console.log(html);
});
});