tt-help-cli-ycl 1.3.11 → 1.3.13
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 +17 -17
- package/cli.js +9 -9
- package/package.json +45 -46
- package/{bat → scripts}/run-explore.bat +68 -68
- package/{bat → scripts}/run-explore.ps1 +81 -81
- package/{bat → scripts}/run-explore.sh +73 -73
- package/scripts/test-captcha-lib.mjs +68 -0
- package/scripts/test-captcha.mjs +81 -0
- package/scripts/test-incognito-lib.mjs +36 -0
- package/scripts/test-login-state.mjs +128 -0
- package/scripts/test-safe-click.mjs +45 -0
- package/src/cli/auto.js +186 -157
- package/src/cli/config.js +116 -0
- package/src/cli/explore-default.js +83 -0
- package/src/cli/explore.js +227 -181
- package/src/cli/progress.js +111 -111
- package/src/cli/refresh.js +216 -0
- package/src/cli/scrape.js +47 -47
- package/src/cli/utils.js +18 -18
- package/src/cli/videos.js +41 -41
- package/src/cli/watch.js +31 -31
- package/src/lib/args.js +456 -391
- package/src/lib/browser/anti-detect.js +23 -23
- package/src/lib/browser/cdp.js +194 -142
- package/src/lib/browser/launch.js +43 -43
- package/src/lib/browser/page.js +146 -87
- package/src/lib/constants.js +119 -119
- package/src/lib/delay.js +54 -54
- package/src/lib/explore-fetch.js +118 -118
- package/src/lib/fetcher.js +45 -45
- package/src/lib/filter.js +66 -66
- package/src/lib/io.js +54 -54
- package/src/lib/output.js +80 -80
- package/src/{scraper/modules/page-error-detector.mjs → lib/page-error-detector.js} +70 -70
- package/src/lib/parser.js +47 -47
- package/src/lib/retry.js +45 -45
- package/src/lib/scrape.js +40 -40
- package/src/{scraper/modules/scroll-collector.mjs → lib/scroll-collector.js} +231 -189
- package/src/lib/url.js +52 -52
- package/src/main.js +48 -0
- package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
- package/src/scraper/{auto-core.mjs → auto-core.js} +203 -194
- package/src/scraper/{core.mjs → core.js} +211 -190
- package/src/scraper/{explore-core.mjs → explore-core.js} +180 -171
- package/src/scraper/modules/{captcha-handler.mjs → captcha-handler.js} +114 -114
- package/src/scraper/modules/{comment-extractor.mjs → comment-extractor.js} +74 -69
- package/src/scraper/modules/{follow-extractor.mjs → follow-extractor.js} +121 -121
- package/src/scraper/modules/{guess-extractor.mjs → guess-extractor.js} +51 -51
- package/src/scraper/modules/page-error-detector.js +1 -0
- package/src/scraper/modules/{page-helpers.mjs → page-helpers.js} +48 -48
- package/src/scraper/modules/scroll-collector.js +8 -0
- package/src/scraper/refresh-core.js +179 -0
- package/src/videos/{core.mjs → core.js} +126 -126
- package/src/watch/data-store.js +431 -0
- package/src/watch/public/index.html +721 -690
- package/src/watch/{server.mjs → server.js} +484 -349
- package/src/main.mjs +0 -234
- package/src/test-auto-follow.cjs +0 -109
- package/src/test-extractors.cjs +0 -75
- package/src/test-follow.cjs +0 -41
- package/src/watch/data-store.mjs +0 -274
|
@@ -1,69 +1,74 @@
|
|
|
1
|
-
import { delay, getDelayConfig, closeCommentPanel } from "./page-helpers.
|
|
2
|
-
import { scrollAndCollect } from "./scroll-collector.
|
|
3
|
-
import { waitAndGetCaptcha } from "./captcha-handler.
|
|
4
|
-
|
|
5
|
-
async function openCommentPanel(page) {
|
|
6
|
-
const tabs = page.locator('[class*="tabbar-item"]');
|
|
7
|
-
const commentTab = tabs.filter({ hasText: "评论" }).first();
|
|
8
|
-
await commentTab.click();
|
|
9
|
-
|
|
10
|
-
// 等待短暂时间让页面渲染
|
|
11
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
12
|
-
|
|
13
|
-
// 检测验证码
|
|
14
|
-
await waitAndGetCaptcha(page, {
|
|
15
|
-
waitMs: 180000,
|
|
16
|
-
pollInterval: 5000,
|
|
17
|
-
log: console.error,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
await page
|
|
21
|
-
.waitForSelector('[class*="CommentListContainer"]', { timeout: 5000 })
|
|
22
|
-
.catch(() => {});
|
|
23
|
-
await page
|
|
24
|
-
.waitForFunction(
|
|
25
|
-
() => {
|
|
26
|
-
const list = document.querySelector('[class*="CommentListContainer"]');
|
|
27
|
-
return list && list.children.length > 0;
|
|
28
|
-
},
|
|
29
|
-
{ timeout: 10000 },
|
|
30
|
-
)
|
|
31
|
-
.catch(() => {});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
import { delay, getDelayConfig, closeCommentPanel } from "./page-helpers.js";
|
|
2
|
+
import { scrollAndCollect } from "./scroll-collector.js";
|
|
3
|
+
import { waitAndGetCaptcha } from "./captcha-handler.js";
|
|
4
|
+
|
|
5
|
+
async function openCommentPanel(page) {
|
|
6
|
+
const tabs = page.locator('[class*="tabbar-item"]');
|
|
7
|
+
const commentTab = tabs.filter({ hasText: "评论" }).first();
|
|
8
|
+
await commentTab.click();
|
|
9
|
+
|
|
10
|
+
// 等待短暂时间让页面渲染
|
|
11
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
12
|
+
|
|
13
|
+
// 检测验证码
|
|
14
|
+
const captchaResult = await waitAndGetCaptcha(page, {
|
|
15
|
+
waitMs: 180000,
|
|
16
|
+
pollInterval: 5000,
|
|
17
|
+
log: console.error,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await page
|
|
21
|
+
.waitForSelector('[class*="CommentListContainer"]', { timeout: 5000 })
|
|
22
|
+
.catch(() => {});
|
|
23
|
+
await page
|
|
24
|
+
.waitForFunction(
|
|
25
|
+
() => {
|
|
26
|
+
const list = document.querySelector('[class*="CommentListContainer"]');
|
|
27
|
+
return list && list.children.length > 0;
|
|
28
|
+
},
|
|
29
|
+
{ timeout: 10000 },
|
|
30
|
+
)
|
|
31
|
+
.catch(() => {});
|
|
32
|
+
|
|
33
|
+
return { captchaDetected: !!captchaResult.detected };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function extractCommentAuthors(page, maxComments = 10) {
|
|
37
|
+
const panelResult = await openCommentPanel(page);
|
|
38
|
+
|
|
39
|
+
const config = getDelayConfig();
|
|
40
|
+
const allAuthors = await scrollAndCollect(page, {
|
|
41
|
+
container: '[class*="CommentMain"]',
|
|
42
|
+
findScrollable: true,
|
|
43
|
+
collectFn: (container) => {
|
|
44
|
+
const list = document.querySelector('[class*="CommentListContainer"]');
|
|
45
|
+
if (!list) return { items: [] };
|
|
46
|
+
const authors = [];
|
|
47
|
+
Array.from(list.children).forEach((wrapper) => {
|
|
48
|
+
const link = wrapper.querySelector(
|
|
49
|
+
'[class*="UsernameContentWrapper"] a',
|
|
50
|
+
);
|
|
51
|
+
if (link) {
|
|
52
|
+
const href = link.href || link.getAttribute("href");
|
|
53
|
+
const m = href && href.match(/@([^/]+)/);
|
|
54
|
+
if (m) authors.push("@" + m[1]);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return { items: authors };
|
|
58
|
+
},
|
|
59
|
+
uniqueKey: (a) => a,
|
|
60
|
+
maxItems: maxComments,
|
|
61
|
+
delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
|
|
62
|
+
staleThreshold: 2,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await closeCommentPanel(page);
|
|
66
|
+
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
authors: allAuthors.slice(0, maxComments),
|
|
70
|
+
captchaDetected: panelResult.captchaDetected,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { extractCommentAuthors };
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { delay, getDelayConfig } from "./page-helpers.
|
|
2
|
-
import { scrollAndCollect } from "./scroll-collector.
|
|
3
|
-
|
|
4
|
-
const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
|
|
5
|
-
|
|
6
|
-
async function waitForListContent(page, minChildren = 1, timeout = 15000) {
|
|
7
|
-
await page
|
|
8
|
-
.waitForFunction(
|
|
9
|
-
(min) => {
|
|
10
|
-
const container = document.querySelector(
|
|
11
|
-
"[class*=DivUserListContainer]",
|
|
12
|
-
);
|
|
13
|
-
return container && container.children.length >= min;
|
|
14
|
-
},
|
|
15
|
-
minChildren,
|
|
16
|
-
{ timeout },
|
|
17
|
-
)
|
|
18
|
-
.catch(() => {});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function openFollowModal(page) {
|
|
22
|
-
const el = await page.$("[data-e2e=following]");
|
|
23
|
-
if (!el) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
"未找到 [data-e2e=following] 元素,请确认当前页面为用户主页",
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
await el.evaluate((el) => el.parentElement.click());
|
|
29
|
-
await page
|
|
30
|
-
.waitForSelector("[class*=DivUserListContainer]", { timeout: 5000 })
|
|
31
|
-
.catch(() => {
|
|
32
|
-
throw new Error("关注弹窗未出现 DivUserListContainer");
|
|
33
|
-
});
|
|
34
|
-
await waitForListContent(page, 1, 3000);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function switchToFollowersTab(page) {
|
|
38
|
-
await page.evaluate(() => {
|
|
39
|
-
const tabs = document.querySelectorAll("[class*=DivTabItem]");
|
|
40
|
-
for (const tab of tabs) {
|
|
41
|
-
if (tab.textContent?.includes("粉丝")) {
|
|
42
|
-
tab.click();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
throw new Error("未找到粉丝 Tab");
|
|
47
|
-
});
|
|
48
|
-
await waitForListContent(page, 1, 3000);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function closeFollowModal(page) {
|
|
52
|
-
await page.evaluate(() => {
|
|
53
|
-
const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
|
|
54
|
-
if (closeBtn) closeBtn.click();
|
|
55
|
-
});
|
|
56
|
-
await page.waitForTimeout(500);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function createUserCollectFn() {
|
|
60
|
-
return (container) => {
|
|
61
|
-
const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
|
|
62
|
-
const modal = document.querySelector("[class*=eyhy6180]");
|
|
63
|
-
const root = modal || document;
|
|
64
|
-
const users = [];
|
|
65
|
-
const seen = new Set();
|
|
66
|
-
const links = root.querySelectorAll('a[href*="/@"]');
|
|
67
|
-
for (const link of links) {
|
|
68
|
-
const match = link.href.match(/@([^/?]+)/);
|
|
69
|
-
if (!match) continue;
|
|
70
|
-
const handle = "@" + decodeURIComponent(match[1]);
|
|
71
|
-
const text = (link.textContent || "").trim();
|
|
72
|
-
if (text.length <= 2) continue;
|
|
73
|
-
if (FILTER_WORDS.includes(text)) continue;
|
|
74
|
-
if (seen.has(handle)) continue;
|
|
75
|
-
seen.add(handle);
|
|
76
|
-
users.push({ handle, displayName: text });
|
|
77
|
-
}
|
|
78
|
-
return { items: users };
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function extractUsersFromModal(page, maxUsers) {
|
|
83
|
-
const config = getDelayConfig();
|
|
84
|
-
const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
|
|
85
|
-
const maxDelay = Math.max(800, config.commentMax);
|
|
86
|
-
|
|
87
|
-
const allUsers = await scrollAndCollect(page, {
|
|
88
|
-
container: "[class*=DivUserListContainer]",
|
|
89
|
-
findScrollable: false,
|
|
90
|
-
collectFn: createUserCollectFn(),
|
|
91
|
-
uniqueKey: (u) => u.handle,
|
|
92
|
-
maxItems: maxUsers,
|
|
93
|
-
delayRange: [minDelay, maxDelay],
|
|
94
|
-
staleThreshold: 2,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return allUsers.slice(0, maxUsers);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function extractFollowAndFollowers(page, options = {}) {
|
|
101
|
-
const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
|
|
102
|
-
|
|
103
|
-
await openFollowModal(page);
|
|
104
|
-
|
|
105
|
-
const following = await extractUsersFromModal(page, maxFollowing);
|
|
106
|
-
log(` 已关注: ${following.length}`);
|
|
107
|
-
|
|
108
|
-
await switchToFollowersTab(page);
|
|
109
|
-
|
|
110
|
-
const followers = await extractUsersFromModal(page, maxFollowers);
|
|
111
|
-
log(` 粉丝: ${followers.length}`);
|
|
112
|
-
|
|
113
|
-
await closeFollowModal(page);
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
following: following.map((u) => [u.handle, u.displayName]),
|
|
117
|
-
followers: followers.map((u) => [u.handle, u.displayName]),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export { extractFollowAndFollowers };
|
|
1
|
+
import { delay, getDelayConfig } from "./page-helpers.js";
|
|
2
|
+
import { scrollAndCollect } from "./scroll-collector.js";
|
|
3
|
+
|
|
4
|
+
const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
|
|
5
|
+
|
|
6
|
+
async function waitForListContent(page, minChildren = 1, timeout = 15000) {
|
|
7
|
+
await page
|
|
8
|
+
.waitForFunction(
|
|
9
|
+
(min) => {
|
|
10
|
+
const container = document.querySelector(
|
|
11
|
+
"[class*=DivUserListContainer]",
|
|
12
|
+
);
|
|
13
|
+
return container && container.children.length >= min;
|
|
14
|
+
},
|
|
15
|
+
minChildren,
|
|
16
|
+
{ timeout },
|
|
17
|
+
)
|
|
18
|
+
.catch(() => {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function openFollowModal(page) {
|
|
22
|
+
const el = await page.$("[data-e2e=following]");
|
|
23
|
+
if (!el) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"未找到 [data-e2e=following] 元素,请确认当前页面为用户主页",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
await el.evaluate((el) => el.parentElement.click());
|
|
29
|
+
await page
|
|
30
|
+
.waitForSelector("[class*=DivUserListContainer]", { timeout: 5000 })
|
|
31
|
+
.catch(() => {
|
|
32
|
+
throw new Error("关注弹窗未出现 DivUserListContainer");
|
|
33
|
+
});
|
|
34
|
+
await waitForListContent(page, 1, 3000);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function switchToFollowersTab(page) {
|
|
38
|
+
await page.evaluate(() => {
|
|
39
|
+
const tabs = document.querySelectorAll("[class*=DivTabItem]");
|
|
40
|
+
for (const tab of tabs) {
|
|
41
|
+
if (tab.textContent?.includes("粉丝")) {
|
|
42
|
+
tab.click();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error("未找到粉丝 Tab");
|
|
47
|
+
});
|
|
48
|
+
await waitForListContent(page, 1, 3000);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function closeFollowModal(page) {
|
|
52
|
+
await page.evaluate(() => {
|
|
53
|
+
const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
|
|
54
|
+
if (closeBtn) closeBtn.click();
|
|
55
|
+
});
|
|
56
|
+
await page.waitForTimeout(500);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function createUserCollectFn() {
|
|
60
|
+
return (container) => {
|
|
61
|
+
const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
|
|
62
|
+
const modal = document.querySelector("[class*=eyhy6180]");
|
|
63
|
+
const root = modal || document;
|
|
64
|
+
const users = [];
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const links = root.querySelectorAll('a[href*="/@"]');
|
|
67
|
+
for (const link of links) {
|
|
68
|
+
const match = link.href.match(/@([^/?]+)/);
|
|
69
|
+
if (!match) continue;
|
|
70
|
+
const handle = "@" + decodeURIComponent(match[1]);
|
|
71
|
+
const text = (link.textContent || "").trim();
|
|
72
|
+
if (text.length <= 2) continue;
|
|
73
|
+
if (FILTER_WORDS.includes(text)) continue;
|
|
74
|
+
if (seen.has(handle)) continue;
|
|
75
|
+
seen.add(handle);
|
|
76
|
+
users.push({ handle, displayName: text });
|
|
77
|
+
}
|
|
78
|
+
return { items: users };
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function extractUsersFromModal(page, maxUsers) {
|
|
83
|
+
const config = getDelayConfig();
|
|
84
|
+
const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
|
|
85
|
+
const maxDelay = Math.max(800, config.commentMax);
|
|
86
|
+
|
|
87
|
+
const allUsers = await scrollAndCollect(page, {
|
|
88
|
+
container: "[class*=DivUserListContainer]",
|
|
89
|
+
findScrollable: false,
|
|
90
|
+
collectFn: createUserCollectFn(),
|
|
91
|
+
uniqueKey: (u) => u.handle,
|
|
92
|
+
maxItems: maxUsers,
|
|
93
|
+
delayRange: [minDelay, maxDelay],
|
|
94
|
+
staleThreshold: 2,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return allUsers.slice(0, maxUsers);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function extractFollowAndFollowers(page, options = {}) {
|
|
101
|
+
const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
|
|
102
|
+
|
|
103
|
+
await openFollowModal(page);
|
|
104
|
+
|
|
105
|
+
const following = await extractUsersFromModal(page, maxFollowing);
|
|
106
|
+
log(` 已关注: ${following.length}`);
|
|
107
|
+
|
|
108
|
+
await switchToFollowersTab(page);
|
|
109
|
+
|
|
110
|
+
const followers = await extractUsersFromModal(page, maxFollowers);
|
|
111
|
+
log(` 粉丝: ${followers.length}`);
|
|
112
|
+
|
|
113
|
+
await closeFollowModal(page);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
following: following.map((u) => [u.handle, u.displayName]),
|
|
117
|
+
followers: followers.map((u) => [u.handle, u.displayName]),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { extractFollowAndFollowers };
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { delay, getDelayConfig, closeCommentPanel } from './page-helpers.
|
|
2
|
-
import { scrollAndCollect } from './scroll-collector.
|
|
3
|
-
|
|
4
|
-
async function openGuessTab(page) {
|
|
5
|
-
const tabs = page.locator('[class*="tabbar-item"]');
|
|
6
|
-
const guessTab = tabs.filter({ hasText: /猜你喜欢/i }).first();
|
|
7
|
-
await guessTab.click();
|
|
8
|
-
const config = getDelayConfig();
|
|
9
|
-
await delay(Math.round(config.commentMax * 0.5), config.commentMax);
|
|
10
|
-
await page.waitForSelector('[class*="Related"]', { timeout: 5000 }).catch(() => {});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function extractGuessVideos(page, maxVideos = 10) {
|
|
14
|
-
await openGuessTab(page);
|
|
15
|
-
|
|
16
|
-
const config = getDelayConfig();
|
|
17
|
-
const allVideos = await scrollAndCollect(page, {
|
|
18
|
-
container: '[class*="Related"]',
|
|
19
|
-
findScrollable: true,
|
|
20
|
-
collectFn: (container) => {
|
|
21
|
-
const items = [];
|
|
22
|
-
Array.from(container.querySelectorAll('[class*="DivItemContainer"]')).forEach(item => {
|
|
23
|
-
const link = item.querySelector('a[href*="/video/"]');
|
|
24
|
-
if (link) {
|
|
25
|
-
const href = link.href || link.getAttribute('href');
|
|
26
|
-
const m = href && href.match(/@([^/]+)\/video\/(\d+)/);
|
|
27
|
-
if (m) {
|
|
28
|
-
items.push({
|
|
29
|
-
author: '@' + m[1],
|
|
30
|
-
videoId: m[2],
|
|
31
|
-
url: href,
|
|
32
|
-
title: '',
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return { items };
|
|
38
|
-
},
|
|
39
|
-
uniqueKey: (v) => v.videoId,
|
|
40
|
-
maxItems: maxVideos,
|
|
41
|
-
delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
|
|
42
|
-
staleThreshold: 3,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
await closeCommentPanel(page);
|
|
46
|
-
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
47
|
-
|
|
48
|
-
return allVideos.slice(0, maxVideos);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { extractGuessVideos };
|
|
1
|
+
import { delay, getDelayConfig, closeCommentPanel } from './page-helpers.js';
|
|
2
|
+
import { scrollAndCollect } from './scroll-collector.js';
|
|
3
|
+
|
|
4
|
+
async function openGuessTab(page) {
|
|
5
|
+
const tabs = page.locator('[class*="tabbar-item"]');
|
|
6
|
+
const guessTab = tabs.filter({ hasText: /猜你喜欢/i }).first();
|
|
7
|
+
await guessTab.click();
|
|
8
|
+
const config = getDelayConfig();
|
|
9
|
+
await delay(Math.round(config.commentMax * 0.5), config.commentMax);
|
|
10
|
+
await page.waitForSelector('[class*="Related"]', { timeout: 5000 }).catch(() => {});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function extractGuessVideos(page, maxVideos = 10) {
|
|
14
|
+
await openGuessTab(page);
|
|
15
|
+
|
|
16
|
+
const config = getDelayConfig();
|
|
17
|
+
const allVideos = await scrollAndCollect(page, {
|
|
18
|
+
container: '[class*="Related"]',
|
|
19
|
+
findScrollable: true,
|
|
20
|
+
collectFn: (container) => {
|
|
21
|
+
const items = [];
|
|
22
|
+
Array.from(container.querySelectorAll('[class*="DivItemContainer"]')).forEach(item => {
|
|
23
|
+
const link = item.querySelector('a[href*="/video/"]');
|
|
24
|
+
if (link) {
|
|
25
|
+
const href = link.href || link.getAttribute('href');
|
|
26
|
+
const m = href && href.match(/@([^/]+)\/video\/(\d+)/);
|
|
27
|
+
if (m) {
|
|
28
|
+
items.push({
|
|
29
|
+
author: '@' + m[1],
|
|
30
|
+
videoId: m[2],
|
|
31
|
+
url: href,
|
|
32
|
+
title: '',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return { items };
|
|
38
|
+
},
|
|
39
|
+
uniqueKey: (v) => v.videoId,
|
|
40
|
+
maxItems: maxVideos,
|
|
41
|
+
delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
|
|
42
|
+
staleThreshold: 3,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await closeCommentPanel(page);
|
|
46
|
+
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
47
|
+
|
|
48
|
+
return allVideos.slice(0, maxVideos);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { extractGuessVideos };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { detectPageError } from '../../lib/page-error-detector.js';
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
delay,
|
|
3
|
-
getDelayConfig,
|
|
4
|
-
setDelayConfig,
|
|
5
|
-
listDelayPresets,
|
|
6
|
-
DELAY_PRESETS,
|
|
7
|
-
} from '../../lib/delay.js';
|
|
8
|
-
import { ensureBrowserReady } from '../../lib/browser/cdp.js';
|
|
9
|
-
import {
|
|
10
|
-
ensureTikTokPage,
|
|
11
|
-
closeCommentPanel,
|
|
12
|
-
findTikTokPage,
|
|
13
|
-
getOrCreatePage,
|
|
14
|
-
isLoggedIn,
|
|
15
|
-
assertPageUrl,
|
|
16
|
-
} from '../../lib/browser/page.js';
|
|
17
|
-
import { retryWithBackoff, isRetryableError } from '../../lib/retry.js';
|
|
18
|
-
import {
|
|
19
|
-
extractUserSection,
|
|
20
|
-
parseUserSection,
|
|
21
|
-
extractLocationCreated,
|
|
22
|
-
USER_SECTION_SIZE,
|
|
23
|
-
} from '../../lib/parser.js';
|
|
24
|
-
import { detectPageError } from './page-error-detector.
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
delay,
|
|
28
|
-
setDelayConfig,
|
|
29
|
-
getDelayConfig,
|
|
30
|
-
listDelayPresets,
|
|
31
|
-
DELAY_PRESETS,
|
|
32
|
-
ensureBrowserReady,
|
|
33
|
-
ensureTikTokPage,
|
|
34
|
-
closeCommentPanel,
|
|
35
|
-
findTikTokPage,
|
|
36
|
-
getOrCreatePage,
|
|
37
|
-
isLoggedIn,
|
|
38
|
-
assertPageUrl,
|
|
39
|
-
retryWithBackoff,
|
|
40
|
-
isRetryableError,
|
|
41
|
-
extractUserSection,
|
|
42
|
-
parseUserSection,
|
|
43
|
-
extractLocationCreated,
|
|
44
|
-
USER_SECTION_SIZE,
|
|
45
|
-
detectPageError,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const CDP_PORT = 9222;
|
|
1
|
+
import {
|
|
2
|
+
delay,
|
|
3
|
+
getDelayConfig,
|
|
4
|
+
setDelayConfig,
|
|
5
|
+
listDelayPresets,
|
|
6
|
+
DELAY_PRESETS,
|
|
7
|
+
} from '../../lib/delay.js';
|
|
8
|
+
import { ensureBrowserReady } from '../../lib/browser/cdp.js';
|
|
9
|
+
import {
|
|
10
|
+
ensureTikTokPage,
|
|
11
|
+
closeCommentPanel,
|
|
12
|
+
findTikTokPage,
|
|
13
|
+
getOrCreatePage,
|
|
14
|
+
isLoggedIn,
|
|
15
|
+
assertPageUrl,
|
|
16
|
+
} from '../../lib/browser/page.js';
|
|
17
|
+
import { retryWithBackoff, isRetryableError } from '../../lib/retry.js';
|
|
18
|
+
import {
|
|
19
|
+
extractUserSection,
|
|
20
|
+
parseUserSection,
|
|
21
|
+
extractLocationCreated,
|
|
22
|
+
USER_SECTION_SIZE,
|
|
23
|
+
} from '../../lib/parser.js';
|
|
24
|
+
import { detectPageError } from './page-error-detector.js';
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
delay,
|
|
28
|
+
setDelayConfig,
|
|
29
|
+
getDelayConfig,
|
|
30
|
+
listDelayPresets,
|
|
31
|
+
DELAY_PRESETS,
|
|
32
|
+
ensureBrowserReady,
|
|
33
|
+
ensureTikTokPage,
|
|
34
|
+
closeCommentPanel,
|
|
35
|
+
findTikTokPage,
|
|
36
|
+
getOrCreatePage,
|
|
37
|
+
isLoggedIn,
|
|
38
|
+
assertPageUrl,
|
|
39
|
+
retryWithBackoff,
|
|
40
|
+
isRetryableError,
|
|
41
|
+
extractUserSection,
|
|
42
|
+
parseUserSection,
|
|
43
|
+
extractLocationCreated,
|
|
44
|
+
USER_SECTION_SIZE,
|
|
45
|
+
detectPageError,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const CDP_PORT = 9222;
|