From d14ad6ca900c96d599cfe6b355a3276661b27c21 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 22 May 2020 00:15:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=9B=BD=E4=BA=BA?= =?UTF-8?q?=E6=B0=91=E9=93=B6=E8=A1=8C=E6=B2=9F=E9=80=9A=E4=BA=A4=E6=B5=81?= =?UTF-8?q?=E6=96=B0=E9=97=BB=20&=20=E8=B4=A7=E5=B8=81=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E5=8F=B8=E5=85=AC=E5=BC=80=E5=B8=82=E5=9C=BA=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E4=BA=A4=E6=98=93=E5=85=AC=E5=91=8A=20(#4824)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/finance.md | 10 ++++++ lib/router.js | 4 +++ lib/routes/pbc/goutongjiaoliu.js | 53 +++++++++++++++++++++++++++++ lib/routes/pbc/tradeAnnouncement.js | 53 +++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 lib/routes/pbc/goutongjiaoliu.js create mode 100644 lib/routes/pbc/tradeAnnouncement.js diff --git a/docs/finance.md b/docs/finance.md index 54f2d3a196..bbaf9fa198 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -79,3 +79,13 @@ pageClass: routes | announcement | news | research | + +## 中国人民银行 + +### 沟通交流 + + + +### 货币政策司公开市场交易公告 + + diff --git a/lib/router.js b/lib/router.js index 16a77254e3..e634486fa2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2726,4 +2726,8 @@ router.get('/grubstreet', require('./routes/grubstreet/index')); // Aljazeera 半岛网 router.get('/aljazeera/news', require('./routes/aljazeera/news')); +// 中国人民银行 +router.get('/pbc/goutongjiaoliu', require('./routes/pbc/goutongjiaoliu')); +router.get('/pbc/tradeAnnouncement', require('./routes/pbc/tradeAnnouncement')); + module.exports = router; diff --git a/lib/routes/pbc/goutongjiaoliu.js b/lib/routes/pbc/goutongjiaoliu.js new file mode 100644 index 0000000000..c8b71a3ede --- /dev/null +++ b/lib/routes/pbc/goutongjiaoliu.js @@ -0,0 +1,53 @@ +const url = require('url'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.pbc.gov.cn/goutongjiaoliu/113456/113469/index.html`; + + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.goto(link); + const html = await page.evaluate( + () => + // eslint-disable-next-line + document.querySelector('body').innerHTML + ); + const $ = cheerio.load(html); + const list = $('font.newslist_style') + .map((_, item) => { + item = $(item); + const a = item.find('a[title]'); + return { + title: a.text(), + link: url.resolve(`http://www.pbc.gov.cn`, a.attr('href')), + pubDate: new Date(item.next('span.hui12').text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailPage = await browser.newPage(); + await detailPage.goto(item.link); + const detailHtml = await detailPage.evaluate( + () => + // eslint-disable-next-line + document.querySelector('body').innerHTML + ); + const content = cheerio.load(detailHtml); + item.description = content('#zoom').html(); + return item; + }) + ) + ); + + browser.close(); + + ctx.state.data = { + title: '中国人民银行 - 沟通交流', + link: link, + item: items, + }; +}; diff --git a/lib/routes/pbc/tradeAnnouncement.js b/lib/routes/pbc/tradeAnnouncement.js new file mode 100644 index 0000000000..6e82d7c170 --- /dev/null +++ b/lib/routes/pbc/tradeAnnouncement.js @@ -0,0 +1,53 @@ +const url = require('url'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.pbc.gov.cn/zhengcehuobisi/125207/125213/125431/125475/index.html`; + + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.goto(link); + const html = await page.evaluate( + () => + // eslint-disable-next-line + document.querySelector('body').innerHTML + ); + const $ = cheerio.load(html); + const list = $('font.newslist_style') + .map((_, item) => { + item = $(item); + const a = item.find('a[title]'); + return { + title: a.text(), + link: url.resolve(`http://www.pbc.gov.cn`, a.attr('href')), + pubDate: new Date(item.next('span.hui12').text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailPage = await browser.newPage(); + await detailPage.goto(item.link); + const detailHtml = await detailPage.evaluate( + () => + // eslint-disable-next-line + document.querySelector('body').innerHTML + ); + const content = cheerio.load(detailHtml); + item.description = content('#zoom').html(); + return item; + }) + ) + ); + + browser.close(); + + ctx.state.data = { + title: '中国人民银行 - 货币政策司公开市场交易公告', + link: link, + item: items, + }; +};