13 Commits

Author SHA1 Message Date
imsyy
d18d97f72d Merge pull request #128 from wuaishare/master
修复快手接口
2025-12-28 22:55:54 +08:00
xuan
61f89ed13d 修复linux.do接口 2025-12-20 05:33:57 +08:00
xuan
7dc310de43 Update kuaishou.ts
快手路由小修:将 window.__APOLLO_STATE__= 提取为常量 APOLLO_STATE_PREFIX,并去掉 allItems?.forEach 的可选链(allItems 已有默认空数组)。
2025-12-19 06:13:34 +08:00
xuan
7270d9cf16 Update huxiu.ts
updateTime时间格式修正
2025-12-19 06:07:23 +08:00
xuan
17d1658818 虎嗅接口:从移动端页面爬取改为原生feed API
移动端页面内容爬取不稳定,标题和描述拆分易出错;原生feed接口获取的内容更为稳定。
2025-12-19 05:58:16 +08:00
xuan
82f983793c 修复虎嗅接口
改为抓取虎嗅移动端页面的 window.__NUXT__ 内联数据,使用移动 UA/Referer 获取有效列表。
解析 NUxT 数据时处理 moment_id/origin_publish_time,生成正确的链接与时间戳。
重新拆分内容:以首行作标题(去掉末尾句号),其余行合并为描述,避免标题夹带全文、描述为空。
增加结构缺失和解析失败的错误提示,便于排查。
2025-12-18 17:35:48 +08:00
xuan
772f421157 修复快手接口报错 2025-12-18 16:46:16 +08:00
imsyy
c190efd005 Merge pull request #125 from yll14/patch-1
修复微博403问题
2025-12-06 18:45:28 +08:00
洛洛
9801c4c7ff 修复微博403问题
更换了微博的API接口
2025-11-29 15:14:15 +08:00
底层用户
3298e734a0 Merge pull request #121 from wuliaodezhuyanhe2020/master
Merge
2025-10-25 22:42:33 +08:00
猪猪公主z
0a3869f1a2 feat: 支持过滤微博热搜中的广告(FILTER_WEIBO_ADVERTISEMENT=true) 2025-10-17 14:00:48 +08:00
XiaoZhu
10db165fc4 feat: 支持配置Redis数据库索引
fix: 修复微博热榜字段
2025-10-15 17:25:23 +08:00
XiaoZhu
faa6f0225d feat: 支持配置Redis数据库索引
fix: 修复微博热榜字段
2025-10-15 17:12:01 +08:00
8 changed files with 124 additions and 82 deletions

View File

@@ -15,6 +15,7 @@ DISALLOW_ROBOT=true
REDIS_HOST="127.0.0.1"
REDIS_PORT=6379
REDIS_PASSWORD=""
REDIS_DB=0
# 缓存时长( 秒
CACHE_TTL=3600
@@ -27,3 +28,6 @@ USE_LOG_FILE=true
# RSS Mode
RSS_MODE=false
# Weibo
FILTER_WEIBO_ADVERTISEMENT=false

View File

@@ -15,7 +15,9 @@ export type Config = {
REDIS_HOST: string;
REDIS_PORT: number;
REDIS_PASSWORD: string;
REDIS_DB: number;
ZHIHU_COOKIE: string;
FILTER_WEIBO_ADVERTISEMENT: boolean;
};
// 验证并提取环境变量
@@ -52,5 +54,7 @@ export const config: Config = {
REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1",
REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379),
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
REDIS_DB: getNumericEnvVariable("REDIS_DB", 0),
ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "",
FILTER_WEIBO_ADVERTISEMENT: getBooleanEnvVariable("FILTER_WEIBO_ADVERTISEMENT", false),
};

View File

@@ -89,8 +89,10 @@ export type RouterType = {
word_scheme: string;
note: string;
flag_desc: string;
num: number;
// num: number;
desc_extr: number;
onboard_time: number;
pic: string;
};
zhihu: {
target: {

59
src/routes/huxiu.ts Normal file → Executable file
View File

@@ -1,7 +1,7 @@
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
import axios from "axios";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
@@ -16,36 +16,39 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
return routeData;
};
// 标题处理
const titleProcessing = (text: string) => {
const paragraphs = text.split("<br><br>");
const title = paragraphs.shift()?.replace(/。$/, "");
const intro = paragraphs.join("<br><br>");
return { title, intro };
};
const getList = async (noCache: boolean) => {
const url = `https://www.huxiu.com/moment/`;
const result = await get({
url,
noCache,
// PC 端接口
const url = `https://moment-api.huxiu.com/web-v3/moment/feed?platform=www`;
const res = await axios.get(url, {
headers: {
"User-Agent": "Mozilla/5.0",
Referer: "https://www.huxiu.com/moment/",
},
timeout: 10000,
});
// 正则查找
const pattern =
/<script>[\s\S]*?window\.__INITIAL_STATE__\s*=\s*(\{[\s\S]*?\});[\s\S]*?<\/script>/;
const matchResult = result.data.match(pattern);
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
const list: RouterType["huxiu"][] = res.data?.data?.moment_list?.datalist || [];
return {
...result,
data: jsonObject.map((v: RouterType["huxiu"]) => ({
id: v.object_id,
title: titleProcessing(v.content).title,
desc: titleProcessing(v.content).intro,
author: v.user_info.username,
fromCache: false,
updateTime: new Date().toISOString(),
data: list.map((v: RouterType["huxiu"]) => {
const content = (v.content || "").replace(/<br\s*\/?>/gi, "\n");
const [titleLine, ...rest] = content
.split("\n")
.map((s) => s.trim())
.filter(Boolean);
const title = titleLine?.replace(/。$/, "") || "";
const intro = rest.join("\n");
const momentId = v.object_id;
return {
id: momentId,
title,
desc: intro,
author: v.user_info?.username || "",
timestamp: getTime(v.publish_time),
hot: undefined,
url: v.url || `https://www.huxiu.com/moment/${v.object_id}.html`,
mobileUrl: v.url || `https://m.huxiu.com/moment/${v.object_id}.html`,
})),
hot: v.count_info?.agree_num,
url: `https://www.huxiu.com/moment/${momentId}.html`,
mobileUrl: `https://m.huxiu.com/moment/${momentId}.html`,
};
}),
};
};

47
src/routes/kuaishou.ts Normal file → Executable file
View File

@@ -4,6 +4,8 @@ import { get } from "../utils/getData.js";
import { parseChineseNumber } from "../utils/getNum.js";
import UserAgent from "user-agents";
const APOLLO_STATE_PREFIX = "window.__APOLLO_STATE__=";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
const routeData: RouterData = {
@@ -32,21 +34,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(APOLLO_STATE_PREFIX);
if (start === -1) {
throw new Error("快手页面结构变更,未找到 APOLLO_STATE");
}
const scriptSlice = html.slice(start + APOLLO_STATE_PREFIX.length);
const sentinelA = scriptSlice.indexOf(";(function(");
const sentinelB = scriptSlice.indexOf("</script>");
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 }) => {
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}`,

View File

@@ -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,
};
};

View File

@@ -2,6 +2,7 @@ import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
import { config } from "../config";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
@@ -18,35 +19,35 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
};
const getList = async (noCache: boolean) => {
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";
const url = "https://weibo.com/ajax/side/hotSearch";
const result = await get({
url,
noCache,
ttl: 60,
headers: {
Referer: "https://s.weibo.com/top/summary?cate=realtimehot",
"MWeibo-Pwa": "1",
"X-Requested-With": "XMLHttpRequest",
Referer: "https://weibo.com/",
"User-Agent":
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
},
});
const list = result.data.data.cards?.[0]?.card_group;
if (!result.data?.data?.realtime) {
return { ...result, data: [] };
}
const list = result.data.data.realtime;
return {
...result,
data: list.map((v: RouterType["weibo"]) => {
const key = v.word_scheme ? v.word_scheme : `#${v.desc}`;
data: list.map((v: any, index: number) => {
const title = v.word || v.word_scheme || `热搜${index + 1}`;
return {
id: v.itemid,
title: v.desc,
desc: key,
// author: v.flag_desc,
timestamp: getTime(v.onboard_time),
// hot: v.num,
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
mobileUrl: v?.scheme,
id: v.mid || v.word_scheme || `weibo-${index}`,
title: title,
desc: v.word_scheme || `#${title}#`,
timestamp: getTime(v.onboard_time || Date.now()),
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(title)}`,
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(title)}`,
};
}),
};

View File

@@ -26,6 +26,7 @@ const redis = new Redis({
host: config.REDIS_HOST,
port: config.REDIS_PORT,
password: config.REDIS_PASSWORD,
db: config.REDIS_DB,
maxRetriesPerRequest: 5,
// 重试策略:最小延迟 50ms最大延迟 2s
retryStrategy: (times) => Math.min(times * 50, 2000),