From c6f6ea4194e65352e2ec473a6e2ad046dc3f3dbe Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 3 Nov 2020 11:43:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BD=91=E6=98=93=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=86=85=E8=A7=86=E9=A2=91=E6=97=A0=E6=95=88?= =?UTF-8?q?=20(#6091)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/netease/news/rank.js | 54 +++++++++++---------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/lib/routes/netease/news/rank.js b/lib/routes/netease/news/rank.js index 3dd47557d..f593282b6 100644 --- a/lib/routes/netease/news/rank.js +++ b/lib/routes/netease/news/rank.js @@ -43,7 +43,7 @@ const config = { title: '房产', }, game: { - link: '/special/0001386F/rank_game.html', + link: '/special/0001386F/game_rank.html', title: '游戏', }, travel: { @@ -101,10 +101,10 @@ module.exports = async (ctx) => { const list = $('div.tabContents') .eq(time[ctx.params.time].index + (ctx.params.category === 'whole' ? (ctx.params.type === 'click' ? -1 : 2) : ctx.params.type === 'click' ? 0 : 2)) .find('table tbody tr td a') + .slice(0, 15) .map((_, item) => { item = $(item); return { - title: item.text(), link: item.attr('href'), }; }) @@ -115,42 +115,22 @@ module.exports = async (ctx) => { async (item) => await ctx.cache.tryGet(item.link, async () => { try { - let res; - let content; - if (item.link.startsWith('https://ent.163.com')) { - res = await got({ method: 'get', url: item.link, responseType: 'buffer' }); - content = cheerio.load(iconv.decode(res.data, 'gbk')); - } else { - res = await got.get(item.link); - content = cheerio.load(res.data); - } + const category = item.link.split('.163.com')[0].split('//').pop().split('.').pop(); + const link = `https://3g.163.com/${category}/article/${item.link.split('/').pop()}`; + const detailResponse = await got({ + method: 'get', + url: link, + }); + const content = cheerio.load(detailResponse.data); - if (content('#ne_wrap').attr('data-publishtime')) { - // To get pubDate from most pages. + content('.bot_word').remove(); + content('video').each(function () { + content(this).attr('src', content(this).attr('data-src')); + }); - item.pubDate = new Date(content('#ne_wrap').attr('data-publishtime') + ' GMT+8').toUTCString(); - } else if (content('div.headline span').text()) { - // To get pubDate from special pages in Money. - // eg. https://money.163.com/20/0513/14/FCH1G10000259E8J.html - - item.pubDate = new Date(content('div.headline span').text() + ' GMT+8').toUTCString(); - } else if (content('meta[property="article:published_time"]').attr('content')) { - // To get pubDate from pages with image collections. - // eg. http://lady.163.com/photoview/00A70026/115695.html - - item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString(); - } - - if (content('#endText').html()) { - // To get description from most pages. - - item.description = content('#endText').html(); - } else if (content('div.biz_plus_content').html()) { - // To get description from special pages in Money. - // eg. https://money.163.com/20/0513/14/FCH1G10000259E8J.html - - item.description = content('div.biz_plus_content').html(); - } + item.title = content('meta[property="og:title"]').attr('content').replace('_手机网易网', ''); + item.pubDate = content('meta[property="og:release_date"]').attr('content'); + item.description = content('.content').html(); return item; } catch (err) { @@ -162,7 +142,7 @@ module.exports = async (ctx) => { ctx.state.data = { title: `网易新闻${time[ctx.params.time].title}${ctx.params.type === 'click' ? '点击' : '跟帖'}榜 - ${cfg.title}`, - link: rootUrl, + link: currentUrl, item: items, }; };