Add facebook page (#1245)
This commit is contained in:
parent
a39be6d051
commit
ef7e2a395c
|
|
@ -563,6 +563,10 @@ RSSHub 提供下列 API 接口:
|
|||
|
||||
<route name="分区帖子" author="xyqfer" example="/nga/forum/485" path="/nga/forum/:fid" :paramsDesc="['分区 id, 可在分区主页 URL 找到']"/>
|
||||
|
||||
### Facebook
|
||||
|
||||
<route name="粉絲專頁" author="maple3142" example="/facebook/page/SonetPCR" path="/facebook/page/:id" :paramsDesc="['專頁 id']"/>
|
||||
|
||||
## 编程
|
||||
|
||||
### 掘金
|
||||
|
|
|
|||
|
|
@ -904,4 +904,7 @@ router.get('/steam/news/:appids', require('./routes/steam/news'));
|
|||
// 扇贝
|
||||
router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin'));
|
||||
|
||||
// Facebook
|
||||
router.get('/facebook/page/:id', require('./routes/facebook/page'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (url) => {
|
||||
const { data: html } = await axios.get(url);
|
||||
const $ = cheerio.load(html);
|
||||
const $ct = $($('#m_story_permalink_view').get(0)).find('div>div>div>div>p');
|
||||
$ct.find('br').replaceWith('\n');
|
||||
const content = $ct
|
||||
.map((i, p) => $(p).text())
|
||||
.toArray()
|
||||
.join('\n');
|
||||
const { searchParams: q } = new URL(url);
|
||||
return { url: `https://www.facebook.com/story.php?story_fbid=${q.get('story_fbid')}&id=${q.get('id')}`, html, title: $($('h3 strong a').get(0)).text(), content };
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const getArticle = require('./article');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const { data: html } = await axios.get(`https://mbasic.facebook.com/${encodeURIComponent(id)}/`);
|
||||
const $ = cheerio.load(html);
|
||||
ctx.state.data = {
|
||||
title: $('#m-timeline-cover-section h1 span').text(),
|
||||
link: `https://www.facebook.com/${encodeURIComponent(id)}/`,
|
||||
description: $('#sub_profile_pic_content>div>div:nth-child(3) div>span')
|
||||
.find('br')
|
||||
.replaceWith('\n')
|
||||
.text(),
|
||||
item: await Promise.all(
|
||||
$('div[role=article]>div:nth-child(2)>div:nth-child(2)>span+a')
|
||||
.toArray()
|
||||
.map((x) => $(x).attr('href'))
|
||||
.map(async (url) => {
|
||||
const d = await getArticle('https://mbasic.facebook.com' + url);
|
||||
return {
|
||||
title: d.title,
|
||||
description: d.content.replace(/\n/g, '<br>'),
|
||||
link: d.url,
|
||||
};
|
||||
})
|
||||
),
|
||||
};
|
||||
return $;
|
||||
};
|
||||
Loading…
Reference in New Issue