mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
add 虎扑BBS步行街 (#1551)
This commit is contained in:
@@ -599,6 +599,10 @@ RSSHub 提供下列 API 接口:
|
||||
|
||||
<route name="用户动态" author="LogicJake" example="/bihu/activaties/1478342200" path="/bihu/activaties/:id" :paramsDesc="['用户 id']"/>
|
||||
|
||||
### 虎扑
|
||||
|
||||
<route name="虎扑BBS步行街" author="LogicJake" example="/hupu/bxj/bxj/2" path="/hupu/bxj/:id/:order?" :paramsDesc="['栏目id,可在栏目 URL 找到', '排序方式,1最新回帖(默认),2最新发帖']"/>
|
||||
|
||||
## 编程
|
||||
|
||||
### 掘金
|
||||
|
||||
@@ -1044,6 +1044,9 @@ router.get('/gaoqing/latest', require('./routes/gaoqing/latest'));
|
||||
// 轻小说文库
|
||||
router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter'));
|
||||
|
||||
// 虎扑
|
||||
router.get('/hupu/bxj/:id/:order?', require('./routes/hupu/bxj'));
|
||||
|
||||
// 牛客网
|
||||
router.get('/nowcoder/discuss/:type/:order', require('./routes/nowcoder/discuss'));
|
||||
|
||||
|
||||
82
lib/routes/hupu/bxj.js
Normal file
82
lib/routes/hupu/bxj.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'https://bbs.hupu.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const order = ctx.params.order || 1;
|
||||
|
||||
let link = `https://bbs.hupu.com/${id}`;
|
||||
|
||||
let order_name;
|
||||
if (parseInt(order) === 1) {
|
||||
order_name = '最新回帖';
|
||||
} else {
|
||||
order_name = '最新发帖';
|
||||
link += '-postdate-1';
|
||||
}
|
||||
|
||||
const response = await axios.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const type_name = $('span.infoname').text();
|
||||
|
||||
const list = $('ul.for-list li')
|
||||
.slice(0, 10)
|
||||
.map(function() {
|
||||
const info = {
|
||||
title: $(this)
|
||||
.find('div.titlelink.box > a')
|
||||
.text()
|
||||
.trim(),
|
||||
link: $(this)
|
||||
.find('div.titlelink.box > a')
|
||||
.attr('href'),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
for (let i = list.length - 1; i >= 0; i--) {
|
||||
if (!list[i].link.endsWith('html')) {
|
||||
list.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (info) => {
|
||||
const title = info.title;
|
||||
const itemUrl = url.resolve(host, info.link);
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const date = $('#tpc span.stime').text();
|
||||
const description = $('div.quote-content')
|
||||
.html()
|
||||
.trim();
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
description: description,
|
||||
pubDate: new Date(date).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${type_name}${order_name}——虎扑步行街`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user