fix(route): netease 增加从返回消息头获取编码,避免编码错误导致乱码 (#7806)
This commit is contained in:
parent
46a86994f1
commit
bc6cfc8356
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Reference in New Issue