parent
b8cb6f7d37
commit
08fcdb7add
|
|
@ -2001,3 +2001,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
|
|||
| hot | news | scoff | pic | tec | ask |
|
||||
|
||||
</route>
|
||||
|
||||
### 油价
|
||||
|
||||
<route name="今日油价" author="xyqfer" example="/oilprice/shanghai" path="/oilprice/:area" :paramsDesc="['地区拼音,详见[成品油价格网](http://oil.usd-cny.com/)']"/>
|
||||
|
|
|
|||
|
|
@ -689,4 +689,7 @@ router.get('/chouti/:subject?', require('./routes/chouti'));
|
|||
// 西安电子科技大学
|
||||
router.get('/xidian/jwc/:category?', require('./routes/xidian/jwc'));
|
||||
|
||||
// 油价
|
||||
router.get('/oilprice/:area', require('./routes/oilprice'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { area } = ctx.params;
|
||||
const link = 'http://oil.usd-cny.com/';
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: link,
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
|
||||
const $list = $('.pp')
|
||||
.eq(0)
|
||||
.find('table tbody tr');
|
||||
const resultItem = [];
|
||||
let areaName = '';
|
||||
const updateTime = $('.pm')
|
||||
.text()
|
||||
.split(':')[1];
|
||||
const labelList = $list
|
||||
.eq(0)
|
||||
.find('td')
|
||||
.slice(1)
|
||||
.map((index, item) => $(item).text())
|
||||
.get();
|
||||
|
||||
for (let i = 1; i < $list.length; i++) {
|
||||
if (
|
||||
$list
|
||||
.eq(i)
|
||||
.find('td a')
|
||||
.attr('href') === `http://oil.usd-cny.com/${area}.htm`
|
||||
) {
|
||||
const $item = $list.eq(i);
|
||||
areaName = $item.find('td a').text();
|
||||
const description = labelList.reduce((description, label, index) => {
|
||||
description += `
|
||||
<strong>${label}:</strong> ${$item
|
||||
.find('td')
|
||||
.eq(index + 1)
|
||||
.text()}<br>
|
||||
`;
|
||||
return description;
|
||||
}, '');
|
||||
|
||||
resultItem.push({
|
||||
title: `${updateTime}-${areaName}油价`,
|
||||
description,
|
||||
link,
|
||||
guid: updateTime,
|
||||
pubDate: new Date(updateTime).toUTCString(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `今日油价查询-${areaName}`,
|
||||
description: '今日汽油价格查询 最新柴油油价实时行情',
|
||||
link,
|
||||
item: resultItem,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue