koishi-plugin-share-links-analysis 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/parsers/xiaohongshu.js +41 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
- [koishi-plugin-iirose-media-request](https://www.npmjs.com/package/koishi-plugin-iirose-media-request)
|
|
15
15
|
|
|
16
16
|
原项目:[koishi-plugin-bilibili-videolink-analysis](https://github.com/shangxueink/koishi-shangxue-apps/tree/main/plugins/bilibili-videolink-analysis)
|
|
17
|
-
|
|
17
|
+
~~<br>本项目基于原项目0.6.3版本修改~~ 已重构大部分代码
|
|
@@ -34,38 +34,63 @@ async function refreshXhsCookie(ctx, config) {
|
|
|
34
34
|
logger.warn('Puppeteer 服务未启用,无法自动刷新 Cookie。');
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
-
logger.info('
|
|
37
|
+
logger.info('正在执行两步导航策略以刷新小红书 Cookie...');
|
|
38
|
+
let page = null;
|
|
38
39
|
try {
|
|
39
|
-
|
|
40
|
+
page = await ctx.puppeteer.page();
|
|
40
41
|
await page.setUserAgent(config.userAgent);
|
|
42
|
+
// --- 步骤 1: 访问首页,获取基础会话 Cookie (如 web_session) ---
|
|
43
|
+
logger.info('步骤 1/2: 访问首页以获取初始会话 Cookie...');
|
|
41
44
|
try {
|
|
42
|
-
await page.goto('https://www.xiaohongshu.com', {
|
|
43
|
-
waitUntil: '
|
|
45
|
+
await page.goto('https://www.xiaohongshu.com/', {
|
|
46
|
+
waitUntil: 'load',
|
|
44
47
|
timeout: 10000
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
catch (error) {
|
|
48
|
-
logger.error('Puppeteer 访问小红书首页时发生错误:', error);
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const initialCookies = await page.cookies();
|
|
53
|
+
logger.info(`步骤 1 完成, 获取到 ${initialCookies.length} 个初始 Cookie。`);
|
|
54
|
+
// --- 步骤 2: 访问 /explore 页面,触发反爬虫验证,获取安全 Cookie (如 acw_tc) ---
|
|
55
|
+
logger.info('步骤 2/2: 访问 /explore 页面以触发并获取安全 Cookie...');
|
|
56
|
+
try {
|
|
57
|
+
await page.goto('https://www.xiaohongshu.com/explore', {
|
|
58
|
+
waitUntil: 'load',
|
|
59
|
+
timeout: 10000
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
}
|
|
64
|
+
// --- 步骤 3: 收集并验证最终合并的 Cookie ---
|
|
65
|
+
const finalCookies = await page.cookies();
|
|
66
|
+
if (finalCookies.length === 0) {
|
|
67
|
+
logger.warn('执行两步导航后,仍未能获取到任何 Cookie。');
|
|
55
68
|
return false;
|
|
56
69
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
70
|
+
const hasWebSession = finalCookies.some((c) => c.name === 'web_session');
|
|
71
|
+
const hasAcwTc = finalCookies.some((c) => c.name === 'acw_tc');
|
|
72
|
+
const hasABRequestId = finalCookies.some((c) => c.name === 'abRequestId');
|
|
73
|
+
logger.info(`步骤 2 完成, 共获取到 ${finalCookies.length} 个最终 Cookie。`);
|
|
74
|
+
logger.info(`- 是否包含 'web_session': ${hasWebSession ? '是' : '否'}`);
|
|
75
|
+
logger.info(`- 是否包含 'acw_tc': ${hasAcwTc ? '是' : '否'}`);
|
|
76
|
+
logger.info(`- 是否包含 'abRequestId': ${hasABRequestId ? '是' : '否'}`);
|
|
77
|
+
if (!hasWebSession || !hasAcwTc || !hasABRequestId) {
|
|
78
|
+
logger.warn('关键 Cookie 缺失,本次刷新可能不完整。仍将尝试保存。');
|
|
79
|
+
}
|
|
80
|
+
const cookieString = finalCookies.map((c) => `${c.name}=${c.value}`).join('; ');
|
|
60
81
|
await ctx.database.upsert('sla_cookie_cache', [{ platform: platformId, cookie: cookieString }]);
|
|
61
|
-
logger.info('
|
|
62
|
-
await page.close();
|
|
82
|
+
logger.info('成功执行两步刷新策略并缓存了小红书 Cookie!');
|
|
63
83
|
return true;
|
|
64
84
|
}
|
|
65
85
|
catch (error) {
|
|
66
|
-
logger.error('
|
|
86
|
+
logger.error('在执行两步导航刷新 Cookie 时发生错误: ', error);
|
|
67
87
|
return false;
|
|
68
88
|
}
|
|
89
|
+
finally {
|
|
90
|
+
if (page) {
|
|
91
|
+
await page.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
69
94
|
}
|
|
70
95
|
/**
|
|
71
96
|
* 处理单个小红书链接
|
|
@@ -169,7 +194,6 @@ async function process(ctx, config, link, session) {
|
|
|
169
194
|
return null;
|
|
170
195
|
}
|
|
171
196
|
const noteData = pageData.note.noteDetailMap[noteKey].note;
|
|
172
|
-
logger.error(pageData.note);
|
|
173
197
|
// --- 构建结构化数据 ---
|
|
174
198
|
let videoUrl = null;
|
|
175
199
|
let coverUrl = undefined;
|