feat: add 电商报 (#5078)
This commit is contained in:
parent
13070a0274
commit
c21b66ffc8
|
|
@ -429,6 +429,18 @@ Supported sub-sites:
|
|||
|
||||
<Route author="LogicJake" example="/cyzone/label/创业邦周报" path="/cyzone/label/:name" :paramsDesc="['标签名称']"/>
|
||||
|
||||
## 电商报
|
||||
|
||||
### 分区
|
||||
|
||||
<Route author="FlashWingShadow" example="/dsb/area/lingshou" path="/dsb/area/:area" :paramsDesc="['分区']"/>
|
||||
|
||||
area 分区选项
|
||||
|
||||
| 零售 | 物流 | O2O | 金融 | B2B | 人物 | 跨境 | 行业观察 |
|
||||
| -------- | ----- | --- | ------- | --- | ----- | ------- | -------- |
|
||||
| lingshou | wuliu | O2O | jinrong | B2B | renwu | kuajing | guancha |
|
||||
|
||||
## 电商在线
|
||||
|
||||
### 电商在线
|
||||
|
|
|
|||
|
|
@ -2896,4 +2896,7 @@ router.get('/go-weekly', require('./routes/go-weekly'));
|
|||
// AMD
|
||||
router.get('/amd/graphicsdrivers/:id/:rid?', require('./routes/amd/graphicsdrivers'));
|
||||
|
||||
// 电商报
|
||||
router.get('/dsb/area/:area', require('./routes/dsb/area'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const area = ctx.params.area;
|
||||
const host = 'www.dsb.cn';
|
||||
const areaUrl = `http://${host}/${area}`;
|
||||
const areaResp = await got(areaUrl);
|
||||
const $ = cheerio.load(areaResp.data);
|
||||
const areaName = $('.new-list-title').text();
|
||||
const newsUrls = $('ul.new-list-cons > li > a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: `电商报 - ${areaName}`,
|
||||
link: areaUrl,
|
||||
item: await Promise.all(
|
||||
newsUrls.map(
|
||||
async (url) =>
|
||||
await ctx.cache.tryGet(url, async () => {
|
||||
const newsResp = await got(url);
|
||||
const $ = cheerio.load(newsResp.data);
|
||||
return {
|
||||
title: $('.new-content > h2').text(),
|
||||
link: url,
|
||||
pubDate: $('.new-content-info > span:nth-child(3)').text(),
|
||||
description: $('div.new-content-con').html(),
|
||||
};
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue