fix: zhihu (#5834)
This commit is contained in:
parent
0c0bbd4009
commit
2246c5a5e3
|
|
@ -934,7 +934,7 @@ rule
|
|||
|
||||
### 用户回答
|
||||
|
||||
<Route author="DIYgod" example="/zhihu/people/answers/diygod" path="/zhihu/people/answers/:id" :paramsDesc="['作者 id, 可在用户主页 URL 中找到']" anticrawler="1" radar="1"/>
|
||||
<Route author="DIYgod prnake" example="/zhihu/people/answers/diygod" path="/zhihu/people/answers/:id" :paramsDesc="['作者 id, 可在用户主页 URL 中找到']" anticrawler="1" radar="1"/>
|
||||
|
||||
### 用户文章
|
||||
|
||||
|
|
|
|||
|
|
@ -1,68 +1,62 @@
|
|||
const got = require('@/utils/got');
|
||||
const utils = require('./utils');
|
||||
const crypto = require('crypto');
|
||||
const jsencrypt = require('./execlib/jsencrypt');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const d_c0 = await getDC0FromCookies(id);
|
||||
|
||||
const zst81 =
|
||||
'3_2.0ae3TnRUTEvOOUCNMTQnTSHUZo02p-HNMZBO8YD_q2Xtuo_Y0K6P0E6uy-LS9-hp1DufI-we8gGHPgJO1xuPZ0GxCTJHR7820XM20cLRGDJXfgGCBxupMuD_Ic4cpr4w0mRPO7HoY70SfquPmz93mhDQyiqV9ebO1hwOYiiR0ELYuUrxmtDomqU7ynXtOnAoTh_PhRDSTF82VVh29ZhFL1bUYbLgszUc04wFMCrLf9ucOA9HYMGVmzDwyJG2_tJSC4CeTveg11UY9qcX0DhoY2eS1u9efxCVqxGYMhrxyqh2pwucY8bSBwge0Vbx8fBtYWuVMcqumUqSBchLCzJLOErpL3hepEgHfyuYBZrx9oBo1o7NY7CL_fh90Vqkwq9COGMVYzc9BnugLJCw9-GXmShgO0h3KHU2YsQx0zqxY8DNmuUwOMwt1oMOOQvN_iBg8ZqVBtbo_rDwVQvw1JUNmZcN_wBSBAD3KwqN83rO0QTLsWwYC';
|
||||
const zse83 = '3_2.0';
|
||||
|
||||
const path = `/api/v4/members/${id}/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Cexcerpt%2Cis_labeled%2Clabel_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cis_recognized%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics%3Bdata%5B*%5D.question.has_publishing_draft%2Crelationship&offset=0&limit=20&sort_by=created`;
|
||||
const currenURI = `https://www.zhihu.com/people/${id}/answers`;
|
||||
|
||||
const tmp = [zse83, path, currenURI, d_c0, zst81].join('+');
|
||||
const md5 = crypto.createHash('md5');
|
||||
const signature = jsencrypt(md5.update(tmp).digest('hex'));
|
||||
|
||||
const xzseHeaders = {
|
||||
'x-zse-83': zse83,
|
||||
'x-zse-86': '1.0_' + signature,
|
||||
'x-zst-81': zst81,
|
||||
const headers = {
|
||||
'User-Agent': 'ZhihuHybrid com.zhihu.android/Futureve/6.59.0 Mozilla/5.0 (Linux; Android 10; GM1900 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/85.0.4183.127 Mobile Safari/537.36',
|
||||
Referer: `https://www.zhihu.com/people/${id}/answers`,
|
||||
};
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com${path}`,
|
||||
headers: {
|
||||
...utils.header,
|
||||
...xzseHeaders,
|
||||
Referer: `https://www.zhihu.com/people/${id}/answers`,
|
||||
cookie: `d_c0=${d_c0}`,
|
||||
},
|
||||
url: `https://api.zhihu.com/people/${id}/answers?order_by=created&offset=0&limit=10`,
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
const data = response.data.data;
|
||||
let name = data[0].author.name;
|
||||
|
||||
if (name === '知乎用户') {
|
||||
const info = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/api/v4/members/${id}/activities?limit=1`,
|
||||
headers: {
|
||||
...utils.header,
|
||||
Referer: `https://www.zhihu.com/people/${id}/activities`,
|
||||
Authorization: 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20', // hard-coded in js
|
||||
},
|
||||
});
|
||||
name = info.data.data[0].actor.name;
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
let description;
|
||||
const link = `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`;
|
||||
const title = item.question.title;
|
||||
try {
|
||||
const detail = await got({
|
||||
method: 'get',
|
||||
url: `https://api.zhihu.com/appview/api/v4/answers/${item.id}?include=content&is_appview=true`,
|
||||
headers: headers,
|
||||
});
|
||||
description = utils.ProcessImage(detail.data.content);
|
||||
} catch (e) {
|
||||
description = `<a href="${link}" target="_blank">${title}</a>`;
|
||||
}
|
||||
return {
|
||||
title: title,
|
||||
description: description,
|
||||
pubDate: new Date(item.created_time * 1000).toUTCString(),
|
||||
link: link,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data[0].author.name}的知乎回答`,
|
||||
title: `${name}的知乎回答`,
|
||||
link: `https://www.zhihu.com/people/${id}/answers`,
|
||||
description: data[0].author.headline || data[0].author.description,
|
||||
item: data.map((item) => ({
|
||||
title: item.question.title,
|
||||
description: utils.ProcessImage(item.content),
|
||||
pubDate: new Date(item.created_time * 1000).toUTCString(),
|
||||
link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`,
|
||||
})),
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
async function getDC0FromCookies(id) {
|
||||
const url = `https://www.zhihu.com/people/${id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
...utils.header,
|
||||
},
|
||||
});
|
||||
|
||||
const targetCookies = (response.headers['set-cookie'] || []).filter((c) => /d_c0=([^;]+)/.test(c));
|
||||
const matchResult = (targetCookies[0] || '').match(new RegExp('d_c0=([^;]+)'));
|
||||
|
||||
return matchResult[1] || '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ module.exports = async (ctx) => {
|
|||
data: { data },
|
||||
} = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/api/v4/members/${id}/pins?offset=0&limit=20&includes=data%5B*%5D.upvoted_followees%2Cadmin_closed_comment`,
|
||||
url: `https://api.zhihu.com/pins/${id}/moments?limit=10&offset=0`,
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data[0].author.name}的知乎想法`,
|
||||
title: `${data[0].target.author.name}的知乎想法`,
|
||||
link: `https://www.zhihu.com/people/${id}/pins`,
|
||||
item: generateData(data),
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue