fix(route): netease 增加从返回消息头获取编码,避免编码错误导致乱码 (#7806)

This commit is contained in:
murphy 2021-07-17 17:01:03 +08:00 committed by GitHub
parent 46a86994f1
commit bc6cfc8356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ module.exports = async (ctx) => {
const { id } = ctx.params;
const response = await got.get(`http://dy.163.com/v2/article/list.do?pageNo=1&wemediaId=${id}&size=10`);
const charset = response.headers['content-type'].split('=')[1];
const list = response.data.data.list;
let author, link;
@ -26,7 +26,7 @@ module.exports = async (ctx) => {
responseType: 'buffer',
})
).data,
'gbk'
charset
)
);
const $ = cheerio.load(html, { decodeEntities: false });

View File

@ -8,7 +8,8 @@ module.exports = async (ctx) => {
const response = await got.get(url, { responseType: 'buffer' });
const data = iconv.decode(response.data, 'gbk');
const charset = response.headers['content-type'].split('=')[1];
const data = iconv.decode(response.data, charset);
const $ = cheerio.load(data, { decodeEntities: false });
const list = $('.media_articles ul li')
@ -39,7 +40,7 @@ module.exports = async (ctx) => {
responseType: 'buffer',
})
).data,
'gbk'
charset
)
);
content = cheerio.load(itemData, { decodeEntities: false });