feat: add 中国银行外汇牌价 (#2103)

This commit is contained in:
Chenyang Shi
2019-05-12 15:14:27 +08:00
committed by DIYgod
parent cd63190a96
commit 606eb6342b
3 changed files with 52 additions and 0 deletions
+4
View File
@@ -555,6 +555,10 @@ type 为 all 时,category 参数不支持 cost 和 free
<Route name="最新" author="xyqfer" example="/icourse163/newest" path="/icourse163/newest" />
## 中国银行
<Route name="中国银行外汇牌价" author="LogicJake" example="/boc/whpj" path="/boc/whpj" />
## 自如
<Route name="房源" author="DIYgod" example="/ziroom/room/sh/1/2/五角场" path="/ziroom/room/:city/:iswhole/:room/:keyword" :paramsDesc="['城市, 北京 bj; 上海 sh; 深圳 sz; 杭州 hz; 南京 nj; 广州 gz; 成都 cd; 武汉 wh; 天津 tj', '是否整租', '房间数', '关键词']"/>
+3
View File
@@ -1347,6 +1347,9 @@ router.get('/paidai', require('./routes/paidai/index'));
router.get('/paidai/bbs', require('./routes/paidai/bbs'));
router.get('/paidai/news', require('./routes/paidai/news'));
// 中国银行
router.get('/boc/whpj', require('./routes/boc/whpj'));
// 漫画db
router.get('/manhuadb/comics/:id', require('./routes/manhuadb/comics'));
+45
View File
@@ -0,0 +1,45 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'http://www.boc.cn/sourcedb/whpj/';
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const out = $('div.publish table tbody tr')
.slice(2)
.map(function() {
const name = $(this)
.find('td:nth-child(1)')
.text();
const date = `${$(this)
.find('td:nth-child(7)')
.text()} ${$(this)
.find('td:nth-child(8)')
.text()}`;
const info = {
title: name,
description: `现汇买入价:${$(this)
.find('td:nth-child(2)')
.text()}<br>现钞买入价:${$(this)
.find('td:nth-child(3)')
.text()}<br>现汇卖出价:${$(this)
.find('td:nth-child(4)')
.text()}<br>现钞卖出价:${$(this)
.find('td:nth-child(5)')
.text()}<br>中行折算价:${$(this)
.find('td:nth-child(6)')
.text()}<br>`,
pubDate: new Date(date).toUTCString(),
guid: name + date,
};
return info;
})
.get();
ctx.state.data = {
title: '中国银行外汇牌价',
link: link,
item: out,
};
};