From 5cf7f450771f92d7e8f5188e261e6d48a1fd666e Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Fri, 25 Oct 2019 17:26:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=99=8E=E5=97=85?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=B5=84=E8=AE=AF=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=99=8E=E5=97=85=E7=BD=91=E9=A1=B5=E5=85=83=E7=B4=A0=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98=20(#3316?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 4 ++++ lib/router.js | 1 + lib/routes/huxiu/article.js | 30 ++++++++++++++++++++++++++++++ lib/routes/huxiu/tag.js | 2 +- lib/routes/huxiu/utils.js | 10 ++++++++-- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 lib/routes/huxiu/article.js diff --git a/docs/new-media.md b/docs/new-media.md index 078ba0b2e7..af1e8923e4 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -355,6 +355,10 @@ pageClass: routes ## 虎嗅 +### 首页资讯 + + + ### 标签 diff --git a/lib/router.js b/lib/router.js index 897ce2b227..bddaf78914 100644 --- a/lib/router.js +++ b/lib/router.js @@ -995,6 +995,7 @@ router.get('/zimuzu/resource/:id?', require('./routes/zimuzu/resource')); router.get('/huxiu/tag/:id', require('./routes/huxiu/tag')); router.get('/huxiu/search/:keyword', require('./routes/huxiu/search')); router.get('/huxiu/author/:id', require('./routes/huxiu/author')); +router.get('/huxiu/article', require('./routes/huxiu/article')); // Steam router.get('/steam/search/:params', require('./routes/steam/search')); diff --git a/lib/routes/huxiu/article.js b/lib/routes/huxiu/article.js new file mode 100644 index 0000000000..1ecaaaa2b1 --- /dev/null +++ b/lib/routes/huxiu/article.js @@ -0,0 +1,30 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const utils = require('./utils'); + +module.exports = async (ctx) => { + const link = 'https://www.huxiu.com/article'; + const response = await got({ + method: 'get', + url: link, + headers: { + Referer: link, + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.article-item--normal > a, .article-item--large > a') + .slice(0, 10) + .get() + .map((e) => $(e).attr('href')); + + const items = await utils.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '虎嗅网 - 首页资讯', + link, + description: '聚合优质的创新信息与人群,捕获精选 | 深度 | 犀利的商业科技资讯。在虎嗅,不错过互联网的每个重要时刻。', + item: items, + }; +}; diff --git a/lib/routes/huxiu/tag.js b/lib/routes/huxiu/tag.js index 53f9f82544..333c6c8115 100644 --- a/lib/routes/huxiu/tag.js +++ b/lib/routes/huxiu/tag.js @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const items = await utils.ProcessFeed(list, ctx.cache); - const info = `虎嗅 - ${$('.tag-title').text()}`; + const info = `虎嗅 - ${$('h1').text()}`; ctx.state.data = { title: info, link, diff --git a/lib/routes/huxiu/utils.js b/lib/routes/huxiu/utils.js index 7563cd8d6c..bab1b3bb08 100644 --- a/lib/routes/huxiu/utils.js +++ b/lib/routes/huxiu/utils.js @@ -15,13 +15,19 @@ const ProcessFeed = async (list, cache) => { const $ = cheerio.load(response.data); + $('.article__content') + .find('.lazyImg') + .each((i, e) => { + $(e).attr('src', $(e).attr('_src')); + }); + return { title: $('.article__title') .text() .trim(), description: $('.article__top-img-video') + $('.article__content').html(), - pubDate: date($('.article__bottom-content__right .article__time').text(), 8), - author: $('.article__author-info-box .author-info__username').text(), + pubDate: date($('.article__time').text(), 8), + author: $('.author-info__username').text(), link, }; });