mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-19 09:52:21 +08:00
feat: add 马蜂窝自由行攻略 (#4848)
This commit is contained in:
@@ -102,6 +102,14 @@ IATA 国际航空运输协会机场代码,参见[维基百科 国际航空运
|
||||
|
||||
<Route author="sinchang" example="/mafengwo/note/hot" path="/mafengwo/note/:type" :paramsDesc="['目前支持两种, `hot` 代表热门游记, `latest` 代表最新游记']"/>
|
||||
|
||||
### 自由行
|
||||
|
||||
<Route author="nczitzk" example="/mafengwo/ziyouxing/10186" path="/mafengwo/ziyouxing/:code" :paramsDesc="['目的地代码,可在该目的地页面的 URL 中找到']">
|
||||
|
||||
目的地代码请参见 [这里](http://www.mafengwo.cn/mdd/)
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国美术馆
|
||||
|
||||
### 美术馆新闻
|
||||
|
||||
@@ -517,6 +517,7 @@ router.get('/hopper/:lowestOnly/:from/:to?', require('./routes/hopper/index'));
|
||||
|
||||
// 马蜂窝
|
||||
router.get('/mafengwo/note/:type', require('./routes/mafengwo/note'));
|
||||
router.get('/mafengwo/ziyouxing/:code', require('./routes/mafengwo/ziyouxing'));
|
||||
|
||||
// 中国地震局震情速递(与地震台网同步更新)
|
||||
router.get('/earthquake/:region?', require('./routes/earthquake'));
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = `http://www.mafengwo.cn/gonglve/ziyouxing/list/list_page?mddid=${ctx.params.code}&page=1`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data.html);
|
||||
const list = $('div.item')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a');
|
||||
return {
|
||||
title: item.find('h3').text(),
|
||||
link: url.resolve(`http://www.mafengwo.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('span.time').eq(1).find('em').text()).toUTCString();
|
||||
item.description = content('div.sideL').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const titleResponse = await got({
|
||||
method: 'get',
|
||||
url: `http://www.mafengwo.cn/gonglve/ziyouxing/mdd_${ctx.params.code}/`,
|
||||
});
|
||||
const title = cheerio.load(titleResponse.data);
|
||||
|
||||
ctx.state.data = {
|
||||
title: title('title').text(),
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user