mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 07:12:51 +08:00
feat: add 本地宝焦点资讯 (#4549)
This commit is contained in:
@@ -332,6 +332,23 @@ Supported sub-sites:
|
|||||||
|
|
||||||
<Route author="nwindz" example="/hinatazaka46/blog" path="/hinatazaka46/blog" />
|
<Route author="nwindz" example="/hinatazaka46/blog" path="/hinatazaka46/blog" />
|
||||||
|
|
||||||
|
## 本地宝
|
||||||
|
|
||||||
|
### 焦点资讯
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/bendibao/news/bj" path="/bendibao/news/:city" :paramsDesc="['城市缩写']">
|
||||||
|
|
||||||
|
| 城市名 | 缩写 |
|
||||||
|
| ------ | ---- |
|
||||||
|
| 北京 | bj |
|
||||||
|
| 上海 | sh |
|
||||||
|
| 广州 | gz |
|
||||||
|
| 深圳 | sz |
|
||||||
|
|
||||||
|
更多城市请参见 [这里](http://www.bendibao.com/city.htm)
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## 币世界
|
## 币世界
|
||||||
|
|
||||||
### 快讯
|
### 快讯
|
||||||
|
|||||||
@@ -2573,4 +2573,7 @@ router.get('/zhuixinfan/list', require('./routes/zhuixinfan/list'));
|
|||||||
// scoresaber
|
// scoresaber
|
||||||
router.get('/scoresaber/user/:id', require('./routes/scoresaber/user'));
|
router.get('/scoresaber/user/:id', require('./routes/scoresaber/user'));
|
||||||
|
|
||||||
|
// 本地宝焦点资讯
|
||||||
|
router.get('/bendibao/news/:city', require('./routes/bendibao/news'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
52
lib/routes/bendibao/news.js
Normal file
52
lib/routes/bendibao/news.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const city = ctx.params.city;
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `http://${city}.bendibao.com/`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const list = $('ul.focus-news li')
|
||||||
|
.map((_, item) => {
|
||||||
|
item = $(item).find('a');
|
||||||
|
return {
|
||||||
|
title: item.text(),
|
||||||
|
link: item.attr('href'),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
list.map(
|
||||||
|
async (item) =>
|
||||||
|
await ctx.cache.tryGet(item.link, async () => {
|
||||||
|
const detailResponse = await got({ method: 'get', url: item.link });
|
||||||
|
const content = cheerio.load(detailResponse.data);
|
||||||
|
|
||||||
|
// Some links lead to mobile-view pages.
|
||||||
|
// eg. http://m.bj.bendibao.com/news/273517.html
|
||||||
|
// Divs for contents are different from which in desktop-view pages.
|
||||||
|
|
||||||
|
item.description = content('div.content').html() ? content('div.content').html() : content('div.content-box').html();
|
||||||
|
|
||||||
|
// Spans for publish dates are the same cases as above.
|
||||||
|
|
||||||
|
item.pubDate = new Date((content('span.time').text() ? content('span.time').text().replace(/发布时间:/, '') : content('span.public_time').text()) + ' GMT+8').toUTCString();
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title:
|
||||||
|
$('title')
|
||||||
|
.text()
|
||||||
|
.replace(/-爱上本地宝,生活会更好/, '') + `焦点资讯`,
|
||||||
|
link: `http://${city}.bendibao.com/`,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user