请求的接口是:"http://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv125475&productId=1993092&score=0&sortType=5&page=2&pageSize=10&isShadowSku=0&rid=0&fold=1"
网页显示中文正常,返回来的数据中文乱码
const http=require("http");
const fs=require("fs")
// const cheerio=require("cheerio")
// const iconv=require("iconv");
var url="http://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv125475&productId=1993092&score=0&sortType=5&page=2&pageSize=10&isShadowSku=0&rid=0&fold=1";
http.get(url,function (res) {
var html="";
// iconv.decode(res, 'gb2312')
res.setEncoding("utf-8");
res.on("data",function(chunk){
//console.log(chunk.toString())
html+=chunk;
});
res.on("end",function(){
fs.writeFile("./评价.txt",a,function(){
console.log("完成")
})
});
res.on("err",function(){
console.log(err)
})
})
相关分类