diff --git a/docs/README.md b/docs/README.md index 79fca31f7..1413db7c7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -444,6 +444,8 @@ RSSHub 提供下列 API 接口: + + ### Disqus diff --git a/router.js b/router.js index 0340cf214..6994ae3de 100644 --- a/router.js +++ b/router.js @@ -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')); diff --git a/routes/douban/commercialpress/latest.js b/routes/douban/commercialpress/latest.js new file mode 100644 index 000000000..a6232b704 --- /dev/null +++ b/routes/douban/commercialpress/latest.js @@ -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: `
${$item.find('.abstract').html()}`, + pubDate: new Date($item.find('.time > span').attr('title')).toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + title: `商务印书馆-${title}`, + link, + item: resultItem, + }; +};