Skip to content

Commit 574fb66

Browse files
committed
fix(route/qiche365): use set cookie to fix fetch failed issue
1 parent 8ed4034 commit 574fb66

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

β€Žlib/routes/qiche365/recall.tsβ€Ž

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import timezone from '@/utils/timezone';
77

88
const baseUrl = 'https://www.qiche365.org.cn';
99

10+
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
11+
1012
export const route: Route = {
1113
path: '/recall/:channel',
1214
name: 'ζ±½θ½¦ε¬ε›ž',
@@ -16,18 +18,35 @@ export const route: Route = {
1618
| ------------ | ------------ | ------------ | ------------ |
1719
| 1 | 2 | 3 | 4 |`,
1820
categories: ['government'],
21+
features: {
22+
antiCrawler: true,
23+
},
1924
maintainers: ['huanfe1'],
2025
handler,
2126
url: 'qiche365.org.cn/index/recall/index.html',
2227
};
2328

2429
async function handler(ctx): Promise<Data> {
2530
const { channel } = ctx.req.param();
31+
const targetUrl = `${baseUrl}/index/recall/index/item/${channel}.html?loadmore=1`;
32+
33+
// Reason: site uses cookie-based anti-bot β€” first request returns 403 with set-cookie,
34+
// second request with those cookies returns the actual JSON data.
35+
const initResponse = await ofetch.raw(targetUrl, {
36+
headers: {
37+
'User-Agent': userAgent,
38+
'Accept-Language': 'zh-CN,zh;q=0.9',
39+
},
40+
ignoreResponseError: true,
41+
});
42+
43+
const cookies = (initResponse.headers.getSetCookie?.() || []).map((c) => c.split(';')[0]).join('; ');
2644

27-
const { html } = await ofetch(`${baseUrl}/index/recall/index/item/${channel}.html?loadmore=1`, {
28-
method: 'get',
45+
const { html } = await ofetch(targetUrl, {
2946
headers: {
47+
'User-Agent': userAgent,
3048
'Accept-Language': 'zh-CN,zh;q=0.9',
49+
Cookie: cookies,
3150
},
3251
});
3352

@@ -46,7 +65,7 @@ async function handler(ctx): Promise<Data> {
4665
};
4766
});
4867
return {
49-
title: ['ε›½ε†…ε¬ε›žε…¬ε‘Š', 'ε›½ε†…ε¬ε›žζ–°ι—»', 'ε›½ε€–ε¬ε›žε…¬ε‘Š', 'ε›½ε€–ε¬ε›žζ–°ι—»'][channel - 1],
68+
title: ['ε›½ε†…ε¬ε›žζ–°ι—»', 'ε›½ε†…ε¬ε›žε…¬ε‘Š', 'ε›½ε€–ε¬ε›žζ–°ι—»', 'ε›½ε€–ε¬ε›žε…¬ε‘Š'][Number(channel) - 1],
5069
link: `${baseUrl}/index/recall/index.html`,
5170
item: items,
5271
language: 'zh-CN',

0 commit comments

Comments
Β (0)