mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route); zhihu posts (#11084)
This commit is contained in:
+21
-16
@@ -7,15 +7,12 @@ module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const usertype = ctx.params.usertype;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/${usertype}/${id}/posts`,
|
||||
const { data } = await got(`https://www.zhihu.com/${usertype}/${id}/posts`, {
|
||||
headers: {
|
||||
...utils.header,
|
||||
Referer: `https://www.zhihu.com/${usertype}/${id}/`,
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const jsondata = $('#js-initialData');
|
||||
const authorname = $('.ProfileHeader-name')
|
||||
@@ -27,22 +24,30 @@ module.exports = async (ctx) => {
|
||||
const parsed = JSON.parse(jsondata.html());
|
||||
const articlesdata = parsed.initialState.entities.articles;
|
||||
|
||||
const list = [];
|
||||
Object.keys(articlesdata).forEach((v) => {
|
||||
list.push(articlesdata[v]);
|
||||
const list = Object.keys(articlesdata).map((key) => {
|
||||
const $ = cheerio.load(articlesdata[key].content, null, false);
|
||||
$('noscript').remove();
|
||||
$('img').each((_, item) => {
|
||||
if (item.attribs['data-actualsrc'] || item.attribs['data-original']) {
|
||||
item.attribs['data-actualsrc'] = item.attribs['data-actualsrc'] ? item.attribs['data-actualsrc'].split('?source')[0] : null;
|
||||
item.attribs['data-original'] = item.attribs['data-original'] ? item.attribs['data-original'].split('?source')[0] : null;
|
||||
item.attribs.src = item.attribs['data-original'] || item.attribs['data-actualsrc'];
|
||||
delete item.attribs['data-actualsrc'];
|
||||
delete item.attribs['data-original'];
|
||||
}
|
||||
});
|
||||
return {
|
||||
title: articlesdata[key].title,
|
||||
description: $.html(),
|
||||
link: articlesdata[key].url,
|
||||
pubDate: parseDate(articlesdata[key].created, 'X'),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${authorname}的知乎文章`,
|
||||
title: `${authorname} 的知乎文章`,
|
||||
link: `https://www.zhihu.com/${usertype}/${id}/posts`,
|
||||
description: authordescription,
|
||||
item:
|
||||
list.length > 0 &&
|
||||
list.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.content,
|
||||
link: item.url,
|
||||
pubDate: parseDate(item.updated * 1000),
|
||||
})),
|
||||
item: list,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user