From 8c1afe332feeae99d948f3ce20fcbb33c6792585 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Sun, 28 Jul 2019 19:17:14 +0800 Subject: [PATCH] feat: nogizaka46 official website (#2710) Co-authored-by: DIYgod --- docs/other.md | 6 +++++ lib/router.js | 3 +++ lib/routes/nogizaka46/news.js | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 lib/routes/nogizaka46/news.js diff --git a/docs/other.md b/docs/other.md index efcdc6a063..f8d3c8cf93 100644 --- a/docs/other.md +++ b/docs/other.md @@ -689,6 +689,12 @@ type 为 all 时,category 参数不支持 cost 和 free +## 乃木坂 46 官网 + +### 新闻 + + + ## 派代 ### 首页 diff --git a/lib/router.js b/lib/router.js index 5e1b167ab6..c73bc3153b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1583,6 +1583,9 @@ router.get('/yidoutang/case/:type', require('./routes/yidoutang/case.js')); // 开眼 router.get('/kaiyan/index', require('./routes/kaiyan/index')); +// 乃木坂46官网 +router.get('/nogizaka46/news', require('./routes/nogizaka46/news')); + // 阿里云 router.get('/aliyun/database_month', require('./routes/aliyun/database_month')); diff --git a/lib/routes/nogizaka46/news.js b/lib/routes/nogizaka46/news.js new file mode 100644 index 0000000000..b4d9011ab1 --- /dev/null +++ b/lib/routes/nogizaka46/news.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://www.nogizaka46.com/news/', + headers: { + Referer: 'http://www.nogizaka46.com/', + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('#news #sheet div.left div.padding ul li'); + + ctx.state.data = { + allowEmpty: true, + title: '乃木坂46官网 NEWS', + link: 'http://www.nogizaka46.com/news/', + item: + list && + list + .map((index, item) => { + item = $(item); + console.log( + item + .find('.title strong a') + .first() + .text() + ); + return { + title: item + .find('.title strong a') + .first() + .text(), + description: item + .find('.summary') + .first() + .text(), + link: item.find('.title strong a').attr('href'), + pubDate: item + .find('.date') + .first() + .text(), + }; + }) + .get(), + }; +};