From d18fb9a9830e0352fa3bb90f06600ad6e64fae3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E8=A0=A2=E4=BC=9A=E6=AD=BB=E7=9A=84=E6=9F=90?= =?UTF-8?q?=E7=BF=A0?= Date: Mon, 13 Aug 2018 10:45:56 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E8=B4=A2=E6=96=B0=E5=91=A8=E5=88=8A=20(#?= =?UTF-8?q?456)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码格式format了,但是当时报docs/install/README.md和doc/joinus/README.md两个文件没有做format,有点懵,不知道这次能不能过 --- README.md | 2 ++ docs/README.md | 16 +++++++++++ router.js | 3 +++ routes/caixin/weekly.js | 59 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 routes/caixin/weekly.js diff --git a/README.md b/README.md index 4ac5c8051..95a0b8f06 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 专栏文章 - 央视新闻 - 专题 +- 财新网 + - 财新周刊 - Disqus - 评论 - Twitter diff --git a/docs/README.md b/docs/README.md index 62a4762dd..a19ce04ab 100644 --- a/docs/README.md +++ b/docs/README.md @@ -945,6 +945,22 @@ key: 产品密钥 | ----- | ----- | ----- | ---- | ------- | ---- | ---- | | china | world | video | tech | society | law | ent | +## 财新网 + +> 网站部分内容需要付费订阅,RSS 仅做更新提醒,不含付费内容。 + +### 财新周刊 + +举例: [https://rsshub.app/caixin/weekly/coverstory](https://rsshub.app/caixin/weekly/coverstory) + +路由: `/caixin/weekly/:category` + +参数:category,分类名 + +| 封面报道 | 开卷 | 社论 | 时事 | 编辑寄语 | 经济 | 金融 | 商业 | 环境与科技 | 民生 | 副刊 | +| ---------- | ----- | --------- | --------------- | ----------- | ------- | ------- | -------- | ---------------------- | ------- | ------ | +| coverstory | first | editorial | current_affairs | editor_desk | economy | finance | business | environment_technology | cwcivil | column | + ## Disqus ### 评论 diff --git a/router.js b/router.js index a94510a47..898616edc 100755 --- a/router.js +++ b/router.js @@ -332,6 +332,9 @@ router.get('/reimu/tag/:tag', require('./routes/reimu/tag')); // 央视新闻 router.get('/cctv/:category', require('./routes/cctv/category')); +// 财新 +router.get('/caixin/weekly/:category', require('./routes/caixin/weekly')); + // 草榴社区 router.get('/t66y/:id', require('./routes/t66y/index')); diff --git a/routes/caixin/weekly.js b/routes/caixin/weekly.js new file mode 100644 index 000000000..cf599b26a --- /dev/null +++ b/routes/caixin/weekly.js @@ -0,0 +1,59 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const category = ctx.params.category; + const url = `http://weekly.caixin.com/${category}`; + + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + Referer: url, + }, + }); + + const $ = cheerio.load(response.data); + const list = $('.stitXtuwen_list dl dd'); + const items = []; + + for (let i = 0; i < list.length; i++) { + const item = { + title: $(list[i]) + .children('h4') + .children() + .text(), + desc: $(list[i]) + .children('p') + .text(), + pubDate: new Date( + $(list[i]) + .children('span') + .text() + .replace('年', '-') + .replace('月', '-') + .replace('日', '') + ).toUTCString(), + url: $(list[i]) + .children('h4') + .children() + .attr('href'), + }; + items.push(item); + } + + ctx.state.data = { + title: '财新周刊', + link: url, + description: '财新周刊 - 提供财经新闻及资讯服务', + item: items.map((item) => ({ + title: item.title, + description: item.desc, + guid: item.title, + link: item.url, + pubDate: item.pubDate, + })), + }; +};