From bc6cfc8356ce4beb733f3ec96ab5ded458232174 Mon Sep 17 00:00:00 2001 From: murphy Date: Sat, 17 Jul 2021 17:01:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20netease=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BB=8E=E8=BF=94=E5=9B=9E=E6=B6=88=E6=81=AF=E5=A4=B4=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=BC=96=E7=A0=81=EF=BC=8C=E9=81=BF=E5=85=8D=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E4=B9=B1=E7=A0=81?= =?UTF-8?q?=20(#7806)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/netease/dy.js | 4 ++-- lib/routes/netease/dy2.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/routes/netease/dy.js b/lib/routes/netease/dy.js index 51364c675..da60a8472 100644 --- a/lib/routes/netease/dy.js +++ b/lib/routes/netease/dy.js @@ -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 }); diff --git a/lib/routes/netease/dy2.js b/lib/routes/netease/dy2.js index c9344bbf5..9821cdb97 100644 --- a/lib/routes/netease/dy2.js +++ b/lib/routes/netease/dy2.js @@ -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 });