fix zhihu collections (#6815)
This commit is contained in:
parent
be66206a88
commit
72a462de9f
|
|
@ -1094,7 +1094,7 @@ rule
|
|||
|
||||
### 收藏夹
|
||||
|
||||
<Route author="huruji" example="/zhihu/collection/26444956" path="/zhihu/collection/:id" :paramsDesc="['收藏夹 id, 可在收藏夹页面 URL 中找到']" anticrawler="1" radar="1" rssbud="1"/>
|
||||
<Route author="huruji Colin-XKL" example="/zhihu/collection/26444956" path="/zhihu/collection/:id" :paramsDesc="['收藏夹 id, 可在收藏夹页面 URL 中找到']" anticrawler="1" radar="1" rssbud="1"/>
|
||||
|
||||
### 用户动态
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,17 @@ module.exports = async (ctx) => {
|
|||
const id = ctx.params.id;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/api/v4/collections/${id}/items?offset=0&limit=20`,
|
||||
headers: {
|
||||
...utils.header,
|
||||
Referer: `https://www.zhihu.com/collection/${id}`,
|
||||
},
|
||||
});
|
||||
|
||||
const list = response.data.data;
|
||||
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/collection/${id}`,
|
||||
headers: {
|
||||
|
|
@ -14,31 +25,22 @@ module.exports = async (ctx) => {
|
|||
},
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.CollectionDetailPageItem');
|
||||
const meta = response2.data;
|
||||
const $ = cheerio.load(meta);
|
||||
const collection_title = $('.CollectionDetailPageHeader-title').text() + ' - 知乎收藏夹';
|
||||
const collection_description = $('.CollectionDetailPageHeader-description').text();
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
title: `${collection_title}`,
|
||||
link: `https://www.zhihu.com/collection/${id}`,
|
||||
description: $('.CollectionDetailPageHeader-description').text(),
|
||||
description: `${collection_description}`,
|
||||
item:
|
||||
list &&
|
||||
list
|
||||
.map((index, item) => {
|
||||
const $item = $(item);
|
||||
const $title = $item.find('.ContentItem-title a');
|
||||
const linkUrl = new URL($title.attr('href'), 'https://www.zhihu.com/');
|
||||
const image = $item.find('meta[itemprop="image"]').attr('content');
|
||||
const text = $item.find('.CopyrightRichText-richText').text();
|
||||
const content = image ? text + `<img src="${image}">` : text;
|
||||
|
||||
return {
|
||||
title: $title.text(),
|
||||
description: content,
|
||||
link: linkUrl,
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
list.map((item) => ({
|
||||
title: `${item.content.type === 'article' ? item.content.title : item.content.question.title}`,
|
||||
link: `${item.content.url}`,
|
||||
description: `${item.content.content}`,
|
||||
pubDate: new Date((item.content.type === 'article' ? item.content.updated : item.content.updated_time) * 1000).toUTCString(),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue