File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
108export 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 = / < l i c l a s s = " b b s - s l - w e b - p o s t - b o d y " > [ \s \S ] * ?< a h r e f = " ( \/ [ ^ " ] + ?\. h t m l ) " [ ^ > ] * ?c l a s s = " p - t i t l e " [ ^ > ] * > ( [ ^ < ] + ) < \/ 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} )
You can’t perform that action at this time.
0 commit comments