mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +08:00
feat: add dcinside (#4934)
This commit is contained in:
@@ -177,3 +177,9 @@ Type
|
||||
| all | rec |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## dcinside
|
||||
|
||||
### board
|
||||
|
||||
<Route author="zfanta" example="/dcinside/board/programming" path="/dcinside/board/:id" :paramsDesc="['board id']" />
|
||||
|
||||
@@ -686,3 +686,9 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
### はてな匿名ダイアリー - 人気記事アーカイブ
|
||||
|
||||
<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>
|
||||
|
||||
## dcinside
|
||||
|
||||
### board
|
||||
|
||||
<Route author="zfanta" example="/dcinside/board/programming" path="/dcinside/board/:id" :paramsDesc="['board id']" />
|
||||
|
||||
@@ -2814,6 +2814,9 @@ router.get('/gov/caict/bps', require('./routes/gov/caict/bps'));
|
||||
router.get('/gov/caict/qwsj', require('./routes/gov/caict/qwsj'));
|
||||
router.get('/gov/caict/caictgd', require('./routes/gov/caict/caictgd'));
|
||||
|
||||
// dcinside
|
||||
router.get('/dcinside/board/:id', require('./routes/dcinside/board'));
|
||||
|
||||
// 企鹅电竞
|
||||
router.get('/egameqq/room/:id', require('./routes/tencent/egame/room'));
|
||||
|
||||
|
||||
66
lib/routes/dcinside/board.js
Normal file
66
lib/routes/dcinside/board.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const domain = 'https://m.dcinside.com';
|
||||
|
||||
const headers = {
|
||||
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||
'Cache-Control': 'max-age=0',
|
||||
Connection: 'keep-alive',
|
||||
Host: 'm.dcinside.com',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'none',
|
||||
'Sec-Fetch-User': '?1',
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Mobile Safari/537.36',
|
||||
};
|
||||
|
||||
async function getData(ctx, link) {
|
||||
const { body } = await got.get(link, { headers });
|
||||
const $ = cheerio.load(body);
|
||||
const { path } = url.parse(link);
|
||||
const key = `dcinside${path}`;
|
||||
|
||||
let result = await ctx.cache.get(key);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = {
|
||||
title: $('head title').text().trim(),
|
||||
pubDate: new Date($('body > div.container > div > div > section > div.gallview-tit-box > div > ul > li:nth-child(2)').text()),
|
||||
link,
|
||||
description: $('body > div.container > div > div > section > div.gall-thum-btm > div > div.thum-txt').html(),
|
||||
};
|
||||
|
||||
ctx.cache.set(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function getItems(ctx, $) {
|
||||
return Promise.all(
|
||||
$('body > div > div > div > section > ul.gall-detail-lst > li:not([class]) > div > a.lt')
|
||||
.toArray()
|
||||
.map((row) => getData(ctx, row.attribs.href))
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const link = `${domain}/board/${id}`;
|
||||
|
||||
const { body } = await got.get(link, { headers });
|
||||
const $ = cheerio.load(body);
|
||||
const rss = {
|
||||
title: $('head title').text(),
|
||||
description: $('head title').text(),
|
||||
link,
|
||||
item: await getItems(ctx, $),
|
||||
};
|
||||
rss.item = rss.item.sort((a, b) => b.pubDate - a.pubDate);
|
||||
ctx.state.data = rss;
|
||||
};
|
||||
Reference in New Issue
Block a user