add 豆瓣浏览发现页不同内容分类 (#1524)

This commit is contained in:
Chenyang Shi
2019-02-13 12:00:54 +08:00
committed by DIYgod
parent 11fc0dfe09
commit c854ce36b1
3 changed files with 59 additions and 0 deletions

View File

@@ -475,6 +475,8 @@ RSSHub 提供下列 API 接口:
<route name="浏览发现" author="clarkzsd" example="/douban/explore" path="/douban/explore"/> <route name="浏览发现" author="clarkzsd" example="/douban/explore" path="/douban/explore"/>
<route name="浏览发现分栏目" author="LogicJake" example="/douban/explore/column/2" path="/douban/explore_column/:id" :paramsDesc="['分栏目id']"/>
<route name="新书速递" author="fengkx" example="/douban/book/latest" path="douban/book/latest"/> <route name="新书速递" author="fengkx" example="/douban/book/latest" path="douban/book/latest"/>
<route name="最新增加的音乐" author="fengkx xyqfer" example="/douban/music/latest/chinese" path="/douban/music/latest/:area?" :paramsDesc="['区域类型,默认全部']"> <route name="最新增加的音乐" author="fengkx xyqfer" example="/douban/music/latest/chinese" path="/douban/music/latest/:area?" :paramsDesc="['区域类型,默认全部']">

View File

@@ -210,6 +210,7 @@ router.get('/douban/commercialpress/latest', require('./routes/douban/commercial
router.get('/douban/bookstore', require('./routes/douban/bookstore')); router.get('/douban/bookstore', require('./routes/douban/bookstore'));
router.get('/douban/book/rank/:type', require('./routes/douban/book/rank')); router.get('/douban/book/rank/:type', require('./routes/douban/book/rank'));
router.get('/douban/doulist/:id', require('./routes/douban/doulist')); router.get('/douban/doulist/:id', require('./routes/douban/doulist'));
router.get('/douban/explore/column/:id', require('./routes/douban/explore_column'));
// 煎蛋 // 煎蛋
router.get('/jandan/:sub_model', require('./routes/jandan/pic')); router.get('/jandan/:sub_model', require('./routes/jandan/pic'));

View File

@@ -0,0 +1,56 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'https://www.douban.com/explore/column/';
module.exports = async (ctx) => {
const id = ctx.params.id;
const link = url.resolve(host, id);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('div.h1').text();
const list = $('div.item')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('div.title a')
.text(),
link: $(this)
.find('div.title a')
.attr('href'),
author: $(this)
.find('div.usr-pic a')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const author = info.author;
const itemUrl = info.link;
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('#link-report').html();
const single = {
title: title,
link: itemUrl,
description: description,
author: author,
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${title}-豆瓣发现`,
link: link,
item: out,
};
};