fix(route): fetch zhihu column info with signed header (#15982)

This commit is contained in:
15532 2024-06-25 01:32:01 +08:00 committed by GitHub
parent 7456ff027f
commit 72d1f85d2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { header } from './utils';
import { getSignedHeader, header } from './utils';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
@ -56,7 +56,13 @@ async function handler(ctx) {
url = `https://www.zhihu.com/column/${id}`;
}
const infoRes = await got(url);
const signedHeader = await getSignedHeader(url, `https://www.zhihu.com/api/v4/columns/${id}/items`);
const infoRes = await got(url, {
headers: {
...signedHeader,
Referer: url,
},
});
const $ = load(infoRes.data);
const title = $('.css-zyehvu').text();
const description = $('.css-1bnklpv').text();