feat: 游研社支持抓取正文 (#5046)
This commit is contained in:
parent
2e738448a2
commit
62c8a45d1b
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue