|
1 | | -export interface Root { |
2 | | - ok: number |
3 | | - data: Data |
4 | | -} |
5 | | - |
6 | | -export interface Data { |
7 | | - mapi: any[] |
8 | | - cards: Card[] |
9 | | - cardlistInfo: CardlistInfo |
10 | | - scheme: string |
11 | | - showAppTips: number |
12 | | -} |
13 | | - |
14 | | -export interface Card { |
15 | | - card_group: CardGroup[] |
16 | | - card_type: number |
17 | | - show_type: number |
18 | | - itemid?: string |
19 | | - title?: string |
20 | | -} |
21 | | - |
22 | | -export interface CardGroup { |
23 | | - actionlog?: Actionlog |
24 | | - card_type: number |
25 | | - pic?: string |
26 | | - itemid?: string |
27 | | - icon?: string |
28 | | - icon_width?: number |
29 | | - icon_height?: number |
30 | | - desc?: string |
31 | | - scheme: string |
32 | | - desc_extr: any |
33 | | - promotion?: Promotion |
34 | | - display_arrow?: number |
35 | | - show_type?: number |
36 | | - title?: string |
37 | | - is_show_arrow?: number |
38 | | - left_tag_img?: string |
39 | | - sub_title?: string |
40 | | -} |
41 | | - |
42 | | -export interface Actionlog { |
43 | | - luicode: string |
44 | | - lfid: string |
45 | | - uicode: string |
46 | | - act_code: number |
47 | | - act_type: number |
48 | | - fid: string |
49 | | - ext: string |
50 | | -} |
51 | | - |
52 | | -export interface Promotion { |
53 | | - monitor_url: MonitorUrl[] |
54 | | -} |
55 | | - |
56 | | -export interface MonitorUrl { |
57 | | - third_party_click: string |
58 | | - third_party_show: string |
59 | | - type: string |
60 | | - monitor_name?: string |
61 | | -} |
62 | | - |
63 | | -export interface CardlistInfo { |
64 | | - select_id: string |
65 | | - title_top: string |
66 | | - show_style: number |
67 | | - starttime: number |
68 | | - can_shared: number |
69 | | - v_p: string |
70 | | - containerid: string |
71 | | - page_type: string |
72 | | - nick: string |
73 | | - cardlist_head_cards: CardlistHeadCard[] |
74 | | - enable_load_imge_scrolling: number |
75 | | - page_title: string |
76 | | - search_request_id: string |
77 | | - load_more_threshold: number |
78 | | - pagesize: number |
79 | | - page_common_ext: string |
80 | | - cardlist_menus: any[] |
81 | | - total: number |
82 | | - headbg_animation: string |
83 | | - page_size: number |
84 | | - page: any |
85 | | -} |
86 | | - |
87 | | -export interface CardlistHeadCard { |
88 | | - title_top?: string |
89 | | - show_menu: boolean |
90 | | - head_type_name: string |
91 | | - head_type: number |
92 | | - head_data?: HeadData |
93 | | - channel_list?: ChannelList[] |
94 | | -} |
95 | | - |
96 | | -export interface HeadData { |
97 | | - cover_url: string |
98 | | - show_navi_mask: boolean |
99 | | - show_title: boolean |
100 | | - data_type: number |
101 | | - scheme: string |
102 | | -} |
103 | | - |
104 | | -export interface ChannelList { |
105 | | - actionlog: Actionlog2 |
106 | | - scheme: string |
107 | | - containerid: string |
108 | | - name: string |
109 | | - default_add: number |
110 | | - id: number |
111 | | - must_show: number |
112 | | - replaced_name?: string |
113 | | -} |
114 | | - |
115 | | -export interface Actionlog2 { |
116 | | - luicode: string |
117 | | - lfid: string |
118 | | - uicode: string |
119 | | - act_code: number |
120 | | - act_type: number |
121 | | - fid: string |
122 | | - ext: string |
123 | | -} |
| 1 | +import * as cheerio from "cheerio" |
124 | 2 |
|
125 | 3 | export default defineSource(async () => { |
126 | | - const url = "https://m.weibo.cn/api/container/getIndex?containerid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot&title=%E5%BE%AE%E5%8D%9A%E7%83%AD%E6%90%9C&extparam=filter_type%3Drealtimehot%26mi_cid%3D100103%26pos%3D0_0%26c_type%3D30%26display_time%3D1540538388&luicode=10000011&lfid=231583" |
127 | | - const res: Root = await myFetch(url, { |
| 4 | + const baseurl = "https://s.weibo.com" |
| 5 | + const url = `${baseurl}/top/summary?cate=realtimehot` |
| 6 | + |
| 7 | + const html = await myFetch(url, { |
128 | 8 | headers: { |
129 | | - "referer": "https://s.weibo.com/top/summary?cate=realtimehot", |
130 | | - "mweibo-pwa": "1", |
131 | | - "x-requested-with": "XMLHttpRequest", |
| 9 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", |
| 10 | + // https://github.com/v5tech/weibo-trending-hot-search |
| 11 | + "Cookie": "SUB=_2AkMWIuNSf8NxqwJRmP8dy2rhaoV2ygrEieKgfhKJJRMxHRl-yT9jqk86tRB6PaLNvQZR6zYUcYVT1zSjoSreQHidcUq7", |
| 12 | + "referer": url, |
132 | 13 | }, |
133 | 14 | }) |
134 | | - return res.data.cards[0].card_group |
135 | | - .filter((k, i) => i !== 0 && k.desc && !k.actionlog?.ext.includes("ads_word")) |
136 | | - .map((k) => { |
137 | | - return { |
138 | | - id: k.desc!, |
139 | | - title: k.desc!, |
140 | | - extra: { |
141 | | - icon: k.icon && { |
142 | | - url: proxyPicture(k.icon), |
143 | | - scale: 1.5, |
| 15 | + |
| 16 | + const $ = cheerio.load(html) |
| 17 | + |
| 18 | + const rows = $("#pl_top_realtimehot table tbody tr").slice(1) |
| 19 | + |
| 20 | + const hotNews: NewsItem[] = [] |
| 21 | + |
| 22 | + rows.each((_, row) => { |
| 23 | + const $row = $(row) |
| 24 | + const $link = $row.find("td.td-02 a").filter((_, el) => { |
| 25 | + const href = $(el).attr("href") |
| 26 | + return !!(href && !href.includes("javascript:void(0);")) |
| 27 | + }).first() |
| 28 | + |
| 29 | + if ($link.length) { |
| 30 | + const title = $link.text().trim() |
| 31 | + const href = $link.attr("href") |
| 32 | + |
| 33 | + if (title && href) { |
| 34 | + const $flag = $row.find("td.td-03").text().trim() |
| 35 | + const flagUrl = { |
| 36 | + 新: "https://simg.s.weibo.com/moter/flags/1_0.png", |
| 37 | + 热: "https://simg.s.weibo.com/moter/flags/2_0.png", |
| 38 | + }[$flag] |
| 39 | + hotNews.push({ |
| 40 | + id: title, |
| 41 | + title, |
| 42 | + url: `${baseurl}${href}`, |
| 43 | + mobileUrl: `${baseurl}${href}`, |
| 44 | + extra: { |
| 45 | + icon: flagUrl ? { url: proxyPicture(flagUrl), scale: 1.5 } : undefined, |
144 | 46 | }, |
145 | | - }, |
146 | | - url: `https://s.weibo.com/weibo?q=${encodeURIComponent(`#${k.desc}#`)}`, |
147 | | - mobileUrl: k.scheme, |
| 47 | + }) |
148 | 48 | } |
149 | | - }) |
| 49 | + } |
| 50 | + }) |
| 51 | + return hotNews |
150 | 52 | }) |
0 commit comments