From 31c3328845ea7bff9d469ec0725bc4fa5a605c9f Mon Sep 17 00:00:00 2001 From: vhgyux Date: Sat, 7 Jul 2018 10:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=91=E6=8A=80=E6=98=9F?= =?UTF-8?q?=E7=90=83=E9=A6=96=E9=A1=B5=E6=9B=B4=E6=96=B0=20(#344)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ docs/README.md | 8 ++++++++ router.js | 3 +++ routes/kejixingqiu/home.js | 39 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 routes/kejixingqiu/home.js diff --git a/README.md b/README.md index 94cda72c0..c6a338055 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 标签 - 草榴 - 分区帖子 +- 科技星球 + - 首页 ## 鸣谢 diff --git a/docs/README.md b/docs/README.md index 225c3f553..9d95ad81a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1419,3 +1419,11 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 | 技术讨论区 | 新时代的我们 | 达盖尔的旗帜 | | ---------- | ------------ | ------------ | | 7 | 8 | 16 | + +## 科技星球 + +### 首页 + +举例: [https://rsshub.app/kejixingqiu/home](https://rsshub.app/kejixingqiu/home) + +路由: `/kejixingqiu/home` \ No newline at end of file diff --git a/router.js b/router.js index 741a78261..491fce99a 100644 --- a/router.js +++ b/router.js @@ -331,4 +331,7 @@ router.get('/cctv/:category', require('./routes/cctv/category')); // 草榴社区 router.get('/t66y/:id', require('./routes/t66y/index')); +// 科技星球 +router.get('/kejixingqiu/home', require('./routes/kejixingqiu/home')); + module.exports = router; diff --git a/routes/kejixingqiu/home.js b/routes/kejixingqiu/home.js new file mode 100644 index 000000000..78ac259ad --- /dev/null +++ b/routes/kejixingqiu/home.js @@ -0,0 +1,39 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + url: 'http://www.xincheng.tv', + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('.l-news_item'); + + ctx.state.data = { + title: $('title').text(), + link: 'http://www.xincheng.tv', + description: $('meta[name="description"]').attr('content'), + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: `${item.find('.sub1-titile2').text()} - ${item.find('.sub1-titile1').text()}`, + description: item.find('.sub1-new-item').text(), + link: `http://www.xincheng.tv${item + .find('.sub1-titile2') + .parent() + .attr('href')}`, + }; + }) + .get(), + }; +};