feat: 游研社支持抓取正文 (#5046)

This commit is contained in:
black-desk 2020-06-28 11:15:38 +08:00 committed by GitHub
parent 2e738448a2
commit 62c8a45d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 5 deletions

View File

@ -39,9 +39,27 @@ module.exports = async (ctx) => {
})
.get();
ctx.state.data = {
title: '游研社-' + $('title').text(),
link: 'http://www.yystv.cn/b/recommend',
item: first_part.concat(second_part),
};
const items = first_part.concat(second_part);
function getDescription(items) {
return Promise.all(
items.map(async function (currentValue) {
currentValue.description = await ctx.cache.tryGet(currentValue.link, async () => {
const r = await got({
url: currentValue.link,
method: 'get',
});
const $ = cheerio.load(r.data);
return $('.doc-content div').html();
});
return currentValue;
})
);
}
await getDescription(items).then(function () {
ctx.state.data = {
title: '游研社-' + $('title').text(),
link: `http://www.yystv.cn/b/${category}`,
item: items,
};
});
};