From aa507ad43d45540eda741a405ba5f91412e82385 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 8 May 2020 11:14:19 +0800 Subject: [PATCH] feat: add 36kr newsfeed (#4652) --- docs/new-media.md | 10 +++++ lib/router.js | 1 + lib/routes/36kr/news.js | 95 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 lib/routes/36kr/news.js diff --git a/docs/new-media.md b/docs/new-media.md index ee110ce9f..67deebba0 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -6,6 +6,16 @@ pageClass: routes ## 36kr +### 资讯 + + + +| 最新 | 推荐 | 创投 | 中概股 | 汽车 | 科技 | 企服 | 金融 | 生活 | 创新 | 房产 | 职场 | 其他 | +| ------ | --------- | ------- | ------ | ------ | ---------- | ----------------- | ------- | ---- | -------- | ----------- | --------- | ----- | +| latest | recommend | contact | ccs | travel | technology | enterpriseservice | banking | life | innovate | real_estate | workplace | other | + + + ### 快讯 diff --git a/lib/router.js b/lib/router.js index c4ca9c4f6..ef31ee63c 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1111,6 +1111,7 @@ router.get('/tingdiantz/nanjing', require('./routes/tingdiantz/nanjing')); // 36kr router.get('/36kr/search/article/:keyword', require('./routes/36kr/search/article')); router.get('/36kr/newsflashes', require('./routes/36kr/newsflashes')); +router.get('/36kr/news/:caty', require('./routes/36kr/news')); router.get('/36kr/user/:uid', require('./routes/36kr/user')); router.get('/36kr/motif/:mid', require('./routes/36kr/motif')); diff --git a/lib/routes/36kr/news.js b/lib/routes/36kr/news.js new file mode 100644 index 000000000..50e8d3a4e --- /dev/null +++ b/lib/routes/36kr/news.js @@ -0,0 +1,95 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + latest: { + link: '/information/web_news/latest', + title: '最新', + }, + recommend: { + link: '/information/web_recommend', + title: '推荐', + }, + contact: { + link: '/information/contact', + title: '创投', + }, + ccs: { + link: '/information/ccs', + title: '中概股', + }, + travel: { + link: '/information/travel', + title: '汽车', + }, + technology: { + link: '/technology', + title: '科技', + }, + enterpriseservice: { + link: '/information/enterpriseservice', + title: '企服', + }, + banking: { + link: '/information/banking', + title: '金融', + }, + life: { + link: '/information/happy_life', + title: '生活', + }, + innovate: { + link: '/information/innovate', + title: '创新', + }, + estate: { + link: '/information/real_estate', + title: '房产', + }, + workplace: { + link: '/information/web_zhichang', + title: '职场', + }, + other: { + link: '/information/other', + title: '其他', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const newsUrl = url.resolve(`https://36kr.com/`, cfg.link); + const response = await got({ + method: 'get', + url: newsUrl, + }); + + const data = JSON.parse(response.data.match(/