From 0a8f937460deb64e8835bb12bb0607775c126a64 Mon Sep 17 00:00:00 2001 From: epirus Date: Sat, 10 Nov 2018 15:57:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=8F=E6=B5=8E=E8=A7=82?= =?UTF-8?q?=E5=AF=9F=E7=BD=91=20(#1099)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加经济观察网 --- docs/README.md | 10 ++++++++ docs/en/joinus/README.md | 19 +++++++++----- router.js | 3 +++ routes/eeo/index.js | 53 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 routes/eeo/index.js diff --git a/docs/README.md b/docs/README.md index afe66e418..671597d68 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2261,3 +2261,13 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 | hot | pop | + +### 经济观察网 + +category 对应的关键词有 + +| 时事 | 政策 | 证券 | 资本 | 理财 | 新科技 | 大健康 | 房产 | 汽车 | 消费 | 影视 | 娱乐 | 体育 | 教育 | 观察家 | 专栏 | 书评 | 个人历史 | +| ---- | ---- | ---- | ---- | ---- | ------ | ------ | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | -------- | + + + diff --git a/docs/en/joinus/README.md b/docs/en/joinus/README.md index 6604d0a29..059a8fb15 100644 --- a/docs/en/joinus/README.md +++ b/docs/en/joinus/README.md @@ -37,12 +37,19 @@ We welcome all pull requests. Suggestions and feedback are also welcomed [here]( - Use component slot for complicated description: ```vue - - - This route returns a list of flight deals (in most cases, 6 flight deals) for a period defined by Hopper's algorithm, which means the travel date will be totally random (could be tomorrow or 10 months from now). - - For airport IATA code please refer to [Wikipedia List of airports by IATA code](https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A) - + + This route returns a list of flight deals (in most cases, 6 flight deals) for a period defined by Hopper's algorithm, which means the travel date will be totally random (could be tomorrow or 10 months from now). For + airport IATA code please refer to [Wikipedia List of airports by IATA code](https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A) ``` diff --git a/router.js b/router.js index fef1f7bf4..9c45cdd46 100644 --- a/router.js +++ b/router.js @@ -781,4 +781,7 @@ router.get('/xiachufang/user/cooked/:id', require('./routes/xiachufang/user/cook router.get('/xiachufang/user/created/:id', require('./routes/xiachufang/user/created')); router.get('/xiachufang/popular/:timeframe?', require('./routes/xiachufang/popular')); +// 经济观察报 +router.get('/eeo/:category?', require('./routes/eeo/index')); + module.exports = router; diff --git a/routes/eeo/index.js b/routes/eeo/index.js new file mode 100644 index 000000000..8e7ba605b --- /dev/null +++ b/routes/eeo/index.js @@ -0,0 +1,53 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || '观察家'; + const category_url_relation = { + 时事: 'http://www.eeo.com.cn/yaowen/dashi/', + 政策: 'http://www.eeo.com.cn/yaowen/hfggzc/', + 宏观: 'http://www.eeo.com.cn/yaowen/hfshuju/', + 证券: 'http://www.eeo.com.cn/jinrong/zhengquan/', + 资本: 'http://www.eeo.com.cn/jinrong/ziben/', + 理财: 'http://www.eeo.com.cn/jinrong/licai/', + 新科技: 'http://www.eeo.com.cn/shangye/xinnengyuan/', + 大健康: 'http://www.eeo.com.cn/shangye/yiliao/', + 房产: 'http://www.eeo.com.cn/fcqcxf/dichan/', + 汽车: 'http://www.eeo.com.cn/fcqcxf/qiche/', + 消费: 'http://www.eeo.com.cn/fcqcxf/xiaofei/', + 影视: 'http://www.eeo.com.cn/yule/yingshi/', + 娱乐: 'http://www.eeo.com.cn/yule/yule/', + 体育: 'http://www.eeo.com.cn/yule/tiyu/', + 教育: 'http://www.eeo.com.cn/yule/jiaoyu/', + 观察家: 'http://www.eeo.com.cn/gcj/guanchajia/', + 专栏: 'http://www.eeo.com.cn/gcj/zhuanlan/', + 书评: 'http://www.eeo.com.cn/gcj/shuping/', + 个人历史: 'http://www.eeo.com.cn/gcj/lishi/', + }; + + const response = await axios({ + method: 'get', + url: category_url_relation[category], + }); + const data = response.data; + const $ = cheerio.load(data); + const list = $('#lyp_article li').get(); + const result = list.map((item) => ({ + title: $(item) + .find('div span a') + .text(), + description: $(item) + .find('div p') + .text(), + pubDate: new Date().toUTCString(), + link: $(item) + .find('>a') + .attr('href'), + })); + ctx.state.data = { + title: '经济观察网', + link: 'http://www.eeo.com.cn', + description: '经济观察网是《经济观察报》社倾力制作的全新商业资讯平台', + item: result, + }; +};