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, + }; +};