axios 访问京东某个商品获取商品评价信息
相关代码
const axios = require("axios");
(async () => {
const productId = "100002928171";
await axios({
method: "GET",
url: `https://sclub.jd.com/comment/productPageComments.action`,
params: {
productId,
score: 0,
sortType: 5,
page: 0,
pageSize: 10, // 某一页
isShadowSku: 0,
fold: 1
},
headers: {
DNT: 1,
Referer: `https://item.jd.com/${productId}.html`,
"sec-ch-ua": "Google Chrome 74",
"Sec-Fetch-Dest": "script",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-site",
"Sec-Fetch-User": "?F",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
}
}).then(res => console.log(res.data));
})();
你期待的结果是什么?实际看到的错误信息又是什么?
返回数据是中文乱码
我一开始以为axios解析问题然后我用postman模拟了一次访问,得到了中文字体
后来为了验证不是axios的问题,我把postman请求的数据下载下来
结果打开还是乱码
所以现在问题很明显 我应该怎么转码? 还是说axios数据被压缩了 ?
打开postman下载的数据然后用vscode试了编码重新打开 全是乱码。。。
补充。。。用chardet.detect(data.data.comments)
返回字符集 UTF-32BE
请求数据,二进制数据,然后用iconv转码为gb2312就可以了。。。。 此贴结了