Files
RSSHub/lib/v2/douban/commercialpress/latest.js
T
FatpandacandTony 8891ad1020 feat(route): add 豆瓣招聘 and refactor to V2 standard (#8937)
* Add(route): add 豆瓣招聘 and change to V2

* Fix(route): fix typo of filename

* Fix(route): sort routes

* Fix(route): Update lib/v2/douban/router.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-02-02 22:56:13 +08:00

56 lines
1.7 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://site.douban.com/commercialpress/room/827243/';
const { data: roomResponse } = await got({
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 got({
method: 'get',
url: newBookUrl,
headers: {
Referer: link,
},
});
// 这个有个重定向,需要获取到真实地址后添加排序参数后再请求一次
const realUrl = `${newBookLandingPage.request.options.url.href}?sort=time&sub_type=`;
const newBookPage = await got({
method: 'get',
url: realUrl,
headers: {
Referer: link,
},
});
$ = cheerio.load(newBookPage.data);
const resultItem = $('.doulist-item')
.map((_, 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')}" /><br>${$item.find('.abstract').html()}`,
pubDate: new Date($item.find('.time > span').attr('title')).toUTCString(),
};
})
.get();
ctx.state.data = {
title: `商务印书馆-${title}`,
link,
item: resultItem,
};
};