diff --git a/docs/new-media.md b/docs/new-media.md index 5623e00d9..c50b05e76 100755 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -429,6 +429,18 @@ Supported sub-sites: +## 电商报 + +### 分区 + + + +area 分区选项 + +| 零售 | 物流 | O2O | 金融 | B2B | 人物 | 跨境 | 行业观察 | +| -------- | ----- | --- | ------- | --- | ----- | ------- | -------- | +| lingshou | wuliu | O2O | jinrong | B2B | renwu | kuajing | guancha | + ## 电商在线 ### 电商在线 diff --git a/lib/router.js b/lib/router.js index c5e562fa1..c7c392a81 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/dsb/area.js b/lib/routes/dsb/area.js new file mode 100644 index 000000000..3197707ae --- /dev/null +++ b/lib/routes/dsb/area.js @@ -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(), + }; + }) + ) + ), + }; +};