From b72f8778d6077abcf3d59c7abe7552b9a3e04dc3 Mon Sep 17 00:00:00 2001 From: WenryXu Date: Tue, 23 Feb 2021 08:00:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=BA=BF=E6=AC=A7?= =?UTF-8?q?=E7=BD=91=20(#6926)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/new-media.md | 8 +++++++- lib/router.js | 4 ++++ lib/routes/iyiou/index.js | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 lib/routes/iyiou/index.js diff --git a/docs/new-media.md b/docs/new-media.md index fd527c269..e8049c8df 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1907,7 +1907,7 @@ column 为 third 时可选的 category: 优先使用方法一,若是网易号搜索页面搜不到的小众网易号(文章页面不含`data-wemediaid`)则可使用此法。 触发反爬会只抓取到标题,建议自建。 - + ## 网易新闻 @@ -2297,3 +2297,9 @@ QueryString: ### 全文 + +## 亿欧网 + +### 资讯 + + diff --git a/lib/router.js b/lib/router.js index 77201526a..40b5adefe 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3964,7 +3964,11 @@ router.get('/furaffinity/favorites/:username/:nsfw?', require('./routes/furaffin router.get('/furaffinity/submission_comments/:id', require('./routes/furaffinity/submission_comments')); router.get('/furaffinity/journal_comments/:id', require('./routes/furaffinity/journal_comments')); +// 亿欧网 +router.get('/iyiou', require('./routes/iyiou')); + // 香港商报 router.get('/hkcd/pdf', require('./routes/hkcd/pdf')); + module.exports = router; diff --git a/lib/routes/iyiou/index.js b/lib/routes/iyiou/index.js new file mode 100644 index 000000000..e2de3fa4c --- /dev/null +++ b/lib/routes/iyiou/index.js @@ -0,0 +1,41 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const formatPubDate = require('@/utils/date.js'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: `https://www.iyiou.com/news`, + }); + const $ = cheerio.load(response.data); + const postList = $('.list-container').find('.eo-article-column').get(); + const result = await Promise.all( + postList.map(async (item) => { + const title = $(item).find('.eo-hover-child').find('.content').find('a').find('.title').text(); + const link = 'https://www.iyiou.com' + $(item).find('.eo-hover-child').find('a').attr('href'); + const guid = link; + const pubDate = formatPubDate($(item).find('.eo-hover-child').find('.content').find('.eo-post-date').text().replace(' ', '')); + + const single = { + title: title, + link: link, + guid: guid, + pubDate: pubDate, + description: '', + }; + + const description_key = 'iyiou' + guid; + const description_value = await ctx.cache.get(description_key); + + if (description_value) { + single.description = description_value; + } else { + const temp = await got(link); + single.description = $(temp.data).find('.post-body').html(); + ctx.cache.set(description_key, single.description); + } + return Promise.resolve(single); + }) + ); + ctx.state.data = { title: '亿欧网', link: 'https://www.iyiou.com/', item: result }; +};