增加:商务印书馆新书速递 (#928)
- 实现 #894 - 考虑到资源消耗的问题,目前只输出了最近两个月(比如现在是2018年9、10月这一项)下按时间排序(最新的在最前)的第一页新书(看到有些月份有近10页的,全部轮一遍意义不大。没有使用新书信息首页的数据是因为上面貌似是按添加顺序来的,最早添加的在最前面。。。
This commit is contained in:
parent
753b84d02e
commit
c3524ec045
|
|
@ -444,6 +444,8 @@ RSSHub 提供下列 API 接口:
|
|||
|
||||
<route name="热门同城活动" author="xyqfer" example="/douban/event/hot/118172" path="/douban/event/hot/:locationId" :paramsDesc="['位置 id, [同城首页](https://www.douban.com/location)打开控制台执行 `window.__loc_id__` 获取']"/>
|
||||
|
||||
<route name="商务印书馆新书速递" author="xyqfer" example="/douban/commercialpress/latest" path="/douban/commercialpress/latest"/>
|
||||
|
||||
### Disqus
|
||||
|
||||
<route name="评论" author="DIYgod" example="/disqus/posts/diygod-me" path="/disqus/posts/:forum" :paramsDesc="['网站的 disqus name']"/>
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ router.get('/douban/explore', require('./routes/douban/explore'));
|
|||
router.get('/douban/music/latest', require('./routes/douban/latest_music'));
|
||||
router.get('/douban/book/latest', require('./routes/douban/latest_book'));
|
||||
router.get('/douban/event/hot/:locationId', require('./routes/douban/event/hot'));
|
||||
router.get('/douban/commercialpress/latest', require('./routes/douban/commercialpress/latest'));
|
||||
|
||||
// 煎蛋
|
||||
router.get('/jandan/:sub_model', require('./routes/jandan/pic'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
const axios = require('../../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = 'https://site.douban.com/commercialpress/room/827243/';
|
||||
const { data: roomResponse } = await axios({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Referer: 'https://site.douban.com/commercialpress/',
|
||||
},
|
||||
});
|
||||
let $ = cheerio.load(roomResponse);
|
||||
const $mod = $('.mod').eq(0);
|
||||
const title = $mod
|
||||
.find('.hd > h2 span')
|
||||
.eq(0)
|
||||
.text();
|
||||
const newBookUrl = $mod.find('.pl a').attr('href');
|
||||
|
||||
const newBookLandingPage = await axios({
|
||||
method: 'get',
|
||||
url: newBookUrl,
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
// 这个有个重定向,需要获取到真实地址后添加排序参数后再请求一次
|
||||
const realUrl = `${newBookLandingPage.request.res.responseUrl}?sort=time&sub_type=`;
|
||||
const newBookPage = await axios({
|
||||
method: 'get',
|
||||
url: realUrl,
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
$ = cheerio.load(newBookPage.data);
|
||||
const resultItem = $('.doulist-item')
|
||||
.map(function(_, item) {
|
||||
const $item = $(item);
|
||||
|
||||
return {
|
||||
title: $item.find('.title > a').text(),
|
||||
link: $item.find('.title > a').attr('href'),
|
||||
description: `<img src="${$item.find('.post img').attr('src')}" referrerpolicy="no-referrer" /><br>${$item.find('.abstract').html()}`,
|
||||
pubDate: new Date($item.find('.time > span').attr('title')).toUTCString(),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: `商务印书馆-${title}`,
|
||||
link,
|
||||
item: resultItem,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue