From 772f421157bd0a83187e0d3fdc968c314645e8a0 Mon Sep 17 00:00:00 2001 From: xuan <27200289+wuaishare@users.noreply.github.com> Date: Thu, 18 Dec 2025 16:46:16 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BF=AB=E6=89=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/kuaishou.ts | 43 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/routes/kuaishou.ts diff --git a/src/routes/kuaishou.ts b/src/routes/kuaishou.ts old mode 100644 new mode 100755 index def47ca..d6c2a71 --- a/src/routes/kuaishou.ts +++ b/src/routes/kuaishou.ts @@ -32,21 +32,52 @@ const getList = async (noCache: boolean) => { }); const listData: ListItem[] = []; // 获取主要内容 - const pattern = /window.__APOLLO_STATE__=(.*);\(function\(\)/s; - const matchResult = result.data?.match(pattern); - const jsonObject = JSON.parse(matchResult[1])["defaultClient"]; + const html = result.data || ""; + const start = html.indexOf("window.__APOLLO_STATE__="); + if (start === -1) { + throw new Error("快手页面结构变更,未找到 APOLLO_STATE"); + } + const scriptSlice = html.slice(start + "window.__APOLLO_STATE__=".length); + const sentinelA = scriptSlice.indexOf(";(function("); + const sentinelB = scriptSlice.indexOf(""); + const cutIndex = + sentinelA !== -1 && sentinelB !== -1 ? Math.min(sentinelA, sentinelB) : Math.max(sentinelA, sentinelB); + if (cutIndex === -1) { + throw new Error("快手页面结构变更,未找到 APOLLO_STATE 结束标记"); + } + const raw = scriptSlice.slice(0, cutIndex).trim().replace(/;$/, ""); + let jsonObject; + try { + // 快手返回的 JSON 末尾常带 undefined/null,需要截断到最后一个 '}' 出现 + const lastBrace = raw.lastIndexOf("}"); + const cleanRaw = lastBrace !== -1 ? raw.slice(0, lastBrace + 1) : raw; + jsonObject = JSON.parse(cleanRaw)["defaultClient"]; + } catch (err) { + const msg = + err instanceof Error + ? `${err.message} | snippet=${raw.slice(0, 200)}...` + : "未知错误"; + throw new Error(`快手数据解析失败: ${msg}`); + } // 获取所有分类 - const allItems = jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']["items"]; + const allItems = + jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']?.items || + jsonObject['$ROOT_QUERY.visionHotRank({"page":"home","platform":"web"})'] + ?.items || + []; // 获取全部热榜 allItems?.forEach((item: { id: string }) => { // 基础数据 const hotItem: RouterType["kuaishou"] = jsonObject[item.id]; + if (!hotItem) return; const id = hotItem.photoIds?.json?.[0]; + const hotValue = hotItem.hotValue ?? ""; + const poster = hotItem.poster ? decodeURIComponent(hotItem.poster) : undefined; listData.push({ id: hotItem.id, title: hotItem.name, - cover: decodeURIComponent(hotItem.poster), - hot: parseChineseNumber(hotItem.hotValue), + cover: poster, + hot: parseChineseNumber(String(hotValue)), timestamp: undefined, url: `https://www.kuaishou.com/short-video/${id}`, mobileUrl: `https://www.kuaishou.com/short-video/${id}`, From 82f983793cf10cfbd1af3e6683dea59c85f5062d Mon Sep 17 00:00:00 2001 From: xuan <27200289+wuaishare@users.noreply.github.com> Date: Thu, 18 Dec 2025 17:35:48 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=99=8E=E5=97=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改为抓取虎嗅移动端页面的 window.__NUXT__ 内联数据,使用移动 UA/Referer 获取有效列表。 解析 NUxT 数据时处理 moment_id/origin_publish_time,生成正确的链接与时间戳。 重新拆分内容:以首行作标题(去掉末尾句号),其余行合并为描述,避免标题夹带全文、描述为空。 增加结构缺失和解析失败的错误提示,便于排查。 --- src/routes/huxiu.ts | 67 +++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 23 deletions(-) mode change 100644 => 100755 src/routes/huxiu.ts diff --git a/src/routes/huxiu.ts b/src/routes/huxiu.ts old mode 100644 new mode 100755 index 7a04b32..8906d13 --- a/src/routes/huxiu.ts +++ b/src/routes/huxiu.ts @@ -16,36 +16,57 @@ export const handleRoute = async (_: undefined, noCache: boolean) => { return routeData; }; -// 标题处理 -const titleProcessing = (text: string) => { - const paragraphs = text.split("

"); - const title = paragraphs.shift()?.replace(/。$/, ""); - const intro = paragraphs.join("

"); - return { title, intro }; -}; - const getList = async (noCache: boolean) => { - const url = `https://www.huxiu.com/moment/`; + // 使用移动端页面,数据通过 window.__NUXT__ 内联 + const url = `https://m.huxiu.com/moment/`; const result = await get({ url, noCache, + headers: { + "User-Agent": + "Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", + Referer: "https://m.huxiu.com/moment/", + }, + responseType: "text", }); - // 正则查找 - const pattern = - /"); const cutIndex = @@ -66,7 +68,7 @@ const getList = async (noCache: boolean) => { ?.items || []; // 获取全部热榜 - allItems?.forEach((item: { id: string }) => { + allItems.forEach((item: { id: string }) => { // 基础数据 const hotItem: RouterType["kuaishou"] = jsonObject[item.id]; if (!hotItem) return; From 61f89ed13d55b29db565bae7d309bfad95d86a15 Mon Sep 17 00:00:00 2001 From: xuan <27200289+wuaishare@users.noreply.github.com> Date: Sat, 20 Dec 2025 05:33:57 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlinux.do=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/linuxdo.ts | 48 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/routes/linuxdo.ts b/src/routes/linuxdo.ts index cab1a87..d541bf4 100644 --- a/src/routes/linuxdo.ts +++ b/src/routes/linuxdo.ts @@ -1,16 +1,7 @@ import type { RouterData } from "../types.js"; import { get } from "../utils/getData.js"; import { getTime } from "../utils/getTime.js"; - -interface Topic { - id: number; - title: string; - excerpt: string; - last_poster_username: string; - created_at: string; - views: number; - like_count: number; -} +import { parseRSS } from "../utils/parseRSS.js"; export const handleRoute = async (_: undefined, noCache: boolean) => { const listData = await getList(noCache); @@ -19,7 +10,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => { title: "Linux.do", type: "热门文章", description: "Linux 技术社区热搜", - link: "https://linux.do/hot", + link: "https://linux.do/top/weekly", total: listData.data?.length || 0, ...listData, }; @@ -27,31 +18,34 @@ export const handleRoute = async (_: undefined, noCache: boolean) => { }; const getList = async (noCache: boolean) => { - const url = "https://linux.do/top/weekly.json"; + const url = "https://linux.do/top.rss?period=weekly"; const result = await get({ url, noCache, headers: { - "Accept": "application/json", - } + "Accept": "application/rss+xml, application/xml;q=0.9, */*;q=0.8", + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + }, }); - - const topics = result.data.topic_list.topics as Topic[]; - const list = topics.map((topic) => { + + const items = await parseRSS(result.data); + const list = items.map((item, index) => { + const link = item.link || ""; return { - id: topic.id, - title: topic.title, - desc: topic.excerpt, - author: topic.last_poster_username, - timestamp: getTime(topic.created_at), - url: `https://linux.do/t/${topic.id}`, - mobileUrl: `https://linux.do/t/${topic.id}`, - hot: topic.views || topic.like_count + id: item.guid || link || index, + title: item.title || "", + desc: item.contentSnippet?.trim() || item.content?.trim() || "", + author: item.author, + timestamp: getTime(item.pubDate || 0), + url: link, + mobileUrl: link, + hot: undefined, }; }); return { ...result, - data: list + data: list, }; -}; \ No newline at end of file +};