Skip to content

Commit 681d137

Browse files
chenxuan520ourongxing
authored andcommitted
fix: Using the hupu official API (#203)
1 parent ca7d647 commit 681d137

1 file changed

Lines changed: 33 additions & 16 deletions

File tree

server/sources/hupu.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
interface Res {
2-
data: {
3-
title: string
4-
hot: string
5-
url: string
6-
mobil_url: string
7-
}[]
1+
interface HotItem {
2+
id: string
3+
title: string
4+
url: string
5+
mobileUrl: string
86
}
97

108
export default defineSource(async () => {
11-
const r: Res = await myFetch(`https://api.vvhan.com/api/hotlist/huPu`)
12-
return r.data.map((k) => {
13-
return {
14-
id: k.url,
15-
title: k.title,
16-
url: k.url,
17-
mobileUrl: k.mobil_url,
18-
}
19-
})
9+
// 获取虎扑新热榜页面的HTML内容
10+
const html = await myFetch(`https://bbs.hupu.com/topic-daily-hot`)
11+
12+
// 正则表达式匹配新的热榜项结构
13+
const regex = /<li class="bbs-sl-web-post-body">[\s\S]*?<a href="(\/[^"]+?\.html)"[^>]*?class="p-title"[^>]*>([^<]+)<\/a>/g
14+
15+
const result: HotItem[] = []
16+
let match
17+
18+
// 将赋值操作移到循环内部,修复no-cond-assign警告
19+
while (true) {
20+
match = regex.exec(html)
21+
if (!match) break
22+
23+
const [, path, title] = match
24+
25+
// 构建完整URL
26+
const url = `https://bbs.hupu.com${path}`
27+
28+
result.push({
29+
id: path,
30+
title: title.trim(),
31+
url,
32+
mobileUrl: url,
33+
})
34+
}
35+
36+
return result
2037
})

0 commit comments

Comments
 (0)