feat: add 三星盖乐世社区最新帖子 (#4887)

This commit is contained in:
Ethan Shen
2020-06-01 12:18:18 +08:00
committed by GitHub
parent 81e0676c94
commit 05d574b572
3 changed files with 51 additions and 0 deletions

View File

@@ -241,6 +241,12 @@ pageClass: routes
<Route author="junfengP" example="/nowcoder/schedule" path="nowcoder/schedule/:propertyId?/:typeId?" :paramsDesc="['行业, 在控制台中抓取接口可获得行业id默认0', '类别,同上']" /> <Route author="junfengP" example="/nowcoder/schedule" path="nowcoder/schedule/:propertyId?/:typeId?" :paramsDesc="['行业, 在控制台中抓取接口可获得行业id默认0', '类别,同上']" />
## 三星盖乐世社区
### 最新帖子
<Route author="nczitzk" example="/samsungmembers/latest" path="/samsungmembers/latest"/>
## 书友社区 ## 书友社区
### 导读 ### 导读

View File

@@ -2799,6 +2799,9 @@ router.get('/law/jh', require('./routes/law/jh'));
// Mobilism // Mobilism
router.get('/mobilism/release', require('./routes/mobilism/release')); router.get('/mobilism/release', require('./routes/mobilism/release'));
// 三星盖乐世社区
router.get('/samsungmembers/latest', require('./routes/samsungmembers/latest'));
// 东莞教研网 // 东莞教研网
router.get('/dgjyw/:type', require('./routes/dgjyw/index')); router.get('/dgjyw/:type', require('./routes/dgjyw/index'));

View File

@@ -0,0 +1,42 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = 'http://www.samsungmembers.cn/bbs/';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.ImgList dl dt')
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: url.resolve('http://www.samsungmembers.cn/', a.attr('href')),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);
item.pubDate = new Date(content('p.data').text() + ' GMT+8').toUTCString();
item.description = content('div.BSHARE_POP').html();
return item;
})
)
);
ctx.state.data = {
title: '三星盖乐世社区 - 最新帖子',
link: currentUrl,
item: items,
};
};