fix(route): zhihu `__zse_ck` (#15707)
This commit is contained in:
parent
532e380a56
commit
94ffb50814
|
|
@ -62,9 +62,25 @@ export const getSignedHeader = async (url: string, apiPath: string) => {
|
|||
|
||||
// fisrt: get cookie(dc_0) from zhihu.com
|
||||
const dc0 = await cache.tryGet('zhihu:cookies:d_c0', async () => {
|
||||
const response = await ofetch.raw(url);
|
||||
const response1 = await ofetch.raw(url);
|
||||
const $ = load(response1._data);
|
||||
const zseCk = $('script:contains("__zse_ck")')
|
||||
.text()
|
||||
.match(/\|\|"(.*?)",.*;document\.cookie/)?.[1];
|
||||
if (!zseCk) {
|
||||
throw new Error('Failed to extract `__zse_ck` from page');
|
||||
}
|
||||
|
||||
const dc0 = response.headers
|
||||
const response2 = await ofetch.raw(url, {
|
||||
headers: {
|
||||
cookie: `${response1.headers
|
||||
.getSetCookie()
|
||||
.map((s) => s.split(';')[0])
|
||||
.join('; ')}; __zse_ck=${zseCk}`,
|
||||
},
|
||||
});
|
||||
|
||||
const dc0 = response2.headers
|
||||
.getSetCookie()
|
||||
.find((s) => s.startsWith('d_c0='))
|
||||
?.split(';')[0];
|
||||
|
|
|
|||
Loading…
Reference in New Issue