tt-help-cli-ycl 1.3.31 → 1.3.33
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/package.json +1 -1
- package/scripts/run-explore copy.bat +35 -2
- package/scripts/run-explore.bat +49 -18
- package/scripts/run-explore.ps1 +51 -5
- package/scripts/run-explore.sh +20 -5
- package/src/cli/explore.js +6 -3
- package/src/lib/api-interceptor.js +110 -37
- package/src/lib/args.js +4 -0
- package/src/scraper/modules/follow-extractor.js +82 -6
- package/src/watch/data-store.js +340 -165
- package/src/watch/server.js +400 -201
|
@@ -3,6 +3,36 @@ import { scrollAndCollect } from "./scroll-collector.js";
|
|
|
3
3
|
|
|
4
4
|
const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
|
|
5
5
|
|
|
6
|
+
const FOLLOW_TRIGGER_SELECTORS = [
|
|
7
|
+
"[data-e2e=following]",
|
|
8
|
+
'a[href$="/following"]',
|
|
9
|
+
'a[href*="/following"]',
|
|
10
|
+
'[data-e2e*="following"]',
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
async function waitForFollowTrigger(page, timeout = 15000) {
|
|
14
|
+
await page
|
|
15
|
+
.waitForFunction(
|
|
16
|
+
(selectors) => {
|
|
17
|
+
for (const selector of selectors) {
|
|
18
|
+
if (document.querySelector(selector)) return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
|
|
22
|
+
const nodes = document.querySelectorAll("a,button,div,span");
|
|
23
|
+
for (const node of nodes) {
|
|
24
|
+
const text = (node.textContent || "").trim();
|
|
25
|
+
if (textMatchers.some((matcher) => matcher.test(text))) return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
FOLLOW_TRIGGER_SELECTORS,
|
|
31
|
+
{ timeout },
|
|
32
|
+
)
|
|
33
|
+
.catch(() => {});
|
|
34
|
+
}
|
|
35
|
+
|
|
6
36
|
async function waitForListContent(page, minChildren = 1, timeout = 15000) {
|
|
7
37
|
await page
|
|
8
38
|
.waitForFunction(
|
|
@@ -19,14 +49,58 @@ async function waitForListContent(page, minChildren = 1, timeout = 15000) {
|
|
|
19
49
|
}
|
|
20
50
|
|
|
21
51
|
async function openFollowModal(page) {
|
|
22
|
-
const
|
|
23
|
-
|
|
52
|
+
const tryOpen = async () =>
|
|
53
|
+
page.evaluate((selectors) => {
|
|
54
|
+
const clickTarget = (node) => {
|
|
55
|
+
if (!node) return false;
|
|
56
|
+
const clickable =
|
|
57
|
+
node.closest('a,button,[role="button"]') ||
|
|
58
|
+
node.parentElement ||
|
|
59
|
+
node;
|
|
60
|
+
clickable.click();
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
for (const selector of selectors) {
|
|
65
|
+
const node = document.querySelector(selector);
|
|
66
|
+
if (clickTarget(node)) return selector;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
|
|
70
|
+
const nodes = Array.from(document.querySelectorAll("a,button,div,span"));
|
|
71
|
+
for (const node of nodes) {
|
|
72
|
+
const text = (node.textContent || "").trim();
|
|
73
|
+
if (!text) continue;
|
|
74
|
+
if (textMatchers.some((matcher) => matcher.test(text))) {
|
|
75
|
+
if (clickTarget(node)) return `text:${text}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return null;
|
|
80
|
+
}, FOLLOW_TRIGGER_SELECTORS);
|
|
81
|
+
|
|
82
|
+
let opened = null;
|
|
83
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
84
|
+
await waitForFollowTrigger(page, attempt === 1 ? 15000 : 8000);
|
|
85
|
+
opened = await tryOpen();
|
|
86
|
+
if (opened) break;
|
|
87
|
+
|
|
88
|
+
await page
|
|
89
|
+
.evaluate(() => {
|
|
90
|
+
window.scrollTo({ top: 0, behavior: "instant" });
|
|
91
|
+
})
|
|
92
|
+
.catch(() => {});
|
|
93
|
+
await delay(800, 1500);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!opened) {
|
|
24
97
|
throw new Error(
|
|
25
|
-
"
|
|
98
|
+
"未找到关注入口元素,请确认当前页面为用户主页或页面结构已变化",
|
|
26
99
|
);
|
|
27
100
|
}
|
|
28
|
-
await
|
|
29
|
-
|
|
101
|
+
await page.waitForSelector("[class*=DivUserListContainer]", {
|
|
102
|
+
timeout: 30000,
|
|
103
|
+
});
|
|
30
104
|
await waitForListContent(page, 1, 5000);
|
|
31
105
|
}
|
|
32
106
|
|
|
@@ -41,7 +115,9 @@ async function switchToFollowersTab(page) {
|
|
|
41
115
|
}
|
|
42
116
|
throw new Error("未找到粉丝 Tab");
|
|
43
117
|
});
|
|
44
|
-
await page.waitForSelector("[class*=DivUserListContainer]", {
|
|
118
|
+
await page.waitForSelector("[class*=DivUserListContainer]", {
|
|
119
|
+
timeout: 30000,
|
|
120
|
+
});
|
|
45
121
|
await waitForListContent(page, 1, 5000);
|
|
46
122
|
}
|
|
47
123
|
|