tt-help-cli-ycl 1.3.48 → 1.3.50
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 +33 -33
- package/cli.js +9 -9
- package/package.json +52 -52
- package/scripts/run-explore copy.bat +101 -101
- package/scripts/run-explore.bat +134 -134
- package/scripts/run-explore.ps1 +159 -159
- package/scripts/run-explore.sh +121 -121
- 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/scripts/test-watch-db-smoke.mjs +246 -0
- package/src/cli/attach.js +331 -331
- package/src/cli/auto.js +265 -265
- package/src/cli/comments.js +620 -620
- package/src/cli/config.js +170 -170
- package/src/cli/db-import.js +51 -51
- package/src/cli/explore.js +555 -555
- package/src/cli/open.js +109 -111
- package/src/cli/progress.js +111 -111
- package/src/cli/refresh.js +288 -288
- package/src/cli/scrape.js +47 -47
- package/src/cli/utils.js +18 -18
- package/src/cli/videos.js +41 -41
- package/src/cli/videostats.js +196 -196
- package/src/cli/watch.js +30 -30
- package/src/lib/api-interceptor.js +161 -161
- package/src/lib/args.js +809 -809
- package/src/lib/browser/anti-detect.js +23 -23
- package/src/lib/browser/cdp.js +261 -261
- package/src/lib/browser/health-checker.js +114 -114
- package/src/lib/browser/launch.js +43 -43
- package/src/lib/browser/page.js +184 -184
- package/src/lib/constants.js +297 -297
- 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/lib/page-error-detector.js +109 -109
- package/src/lib/parse-ssr.mjs +69 -69
- package/src/lib/parser.js +47 -47
- package/src/lib/retry.js +45 -45
- package/src/lib/scrape.js +90 -90
- package/src/lib/target-locations.js +61 -61
- package/src/lib/tiktok-scraper.mjs +98 -61
- package/src/lib/url.js +52 -52
- package/src/main.js +73 -73
- package/src/npm-main.js +70 -70
- package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
- package/src/scraper/auto-core.js +203 -203
- package/src/scraper/core.js +255 -255
- package/src/scraper/explore-core.js +208 -208
- package/src/scraper/modules/captcha-handler.js +114 -114
- package/src/scraper/modules/follow-extractor.js +250 -250
- package/src/scraper/modules/guess-extractor.js +51 -51
- package/src/scraper/modules/page-helpers.js +48 -48
- package/src/scraper/refresh-core.js +213 -213
- package/src/videos/core.js +143 -143
- package/src/watch/data-store.js +2980 -2980
- package/src/watch/public/index.html +2355 -2355
- package/src/watch/server.js +727 -727
package/scripts/run-explore.sh
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
PACKAGENAME="tt-help-cli-ycl"
|
|
4
|
-
CONFIG_PATH="$HOME/.tt-help.json"
|
|
5
|
-
|
|
6
|
-
echo "========================================"
|
|
7
|
-
echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
|
|
8
|
-
echo "========================================"
|
|
9
|
-
|
|
10
|
-
# ---------- 0. 根据本机 IP 自动选择 server ----------
|
|
11
|
-
LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
|
|
12
|
-
|
|
13
|
-
echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
|
|
14
|
-
|
|
15
|
-
if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
|
|
16
|
-
TARGET_SERVER="http://172.18.154.201:3001"
|
|
17
|
-
echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
|
|
18
|
-
else
|
|
19
|
-
TARGET_SERVER="http://117.71.53.99:17301"
|
|
20
|
-
echo "[提示] 未检测到内网 IP,使用公网 server"
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
|
-
# ---------- 1. 检查/安装最新版本 ----------
|
|
24
|
-
LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
|
|
25
|
-
|
|
26
|
-
if [ -z "$LATEST_VERSION" ]; then
|
|
27
|
-
echo "[错误] 无法从 npm 获取最新版本信息"
|
|
28
|
-
exit 1
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
|
|
32
|
-
|
|
33
|
-
if [ -z "$INSTALLED_VERSION" ]; then
|
|
34
|
-
echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
|
|
35
|
-
npm install -g "$PACKAGENAME"
|
|
36
|
-
if [ $? -eq 0 ]; then
|
|
37
|
-
echo "[OK] 安装完成: $LATEST_VERSION"
|
|
38
|
-
else
|
|
39
|
-
echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
|
|
40
|
-
exit 1
|
|
41
|
-
fi
|
|
42
|
-
elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
|
|
43
|
-
echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
|
|
44
|
-
else
|
|
45
|
-
echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
|
|
46
|
-
echo "[执行] 正在升级最新版本..."
|
|
47
|
-
npm install -g "$PACKAGENAME" 2>/dev/null
|
|
48
|
-
if [ $? -eq 0 ]; then
|
|
49
|
-
echo "[OK] 安装完成: $LATEST_VERSION"
|
|
50
|
-
else
|
|
51
|
-
echo "[警告] 自动安装失败,尝试手动更新..."
|
|
52
|
-
npm update -g "$PACKAGENAME"
|
|
53
|
-
fi
|
|
54
|
-
fi
|
|
55
|
-
|
|
56
|
-
# ---------- 2. 检查/设置 server 配置 ----------
|
|
57
|
-
CURRENT_SERVER=""
|
|
58
|
-
if [ -f "$CONFIG_PATH" ]; then
|
|
59
|
-
CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
|
|
63
|
-
echo "[OK] Server 配置正确: $TARGET_SERVER"
|
|
64
|
-
else
|
|
65
|
-
echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
|
|
66
|
-
echo "[执行] 正在设置 server 配置..."
|
|
67
|
-
node -e "
|
|
68
|
-
const fs = require('fs');
|
|
69
|
-
const path = require('path');
|
|
70
|
-
const configPath = path.join(require('os').homedir(), '.tt-help.json');
|
|
71
|
-
let cfg = {};
|
|
72
|
-
try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
|
|
73
|
-
cfg.server = '$TARGET_SERVER';
|
|
74
|
-
fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
|
|
75
|
-
console.log(' 已写入: ' + configPath);
|
|
76
|
-
"
|
|
77
|
-
echo "[OK] Server 配置已设置"
|
|
78
|
-
fi
|
|
79
|
-
|
|
80
|
-
# ---------- 3. 询问用户参数 ----------
|
|
81
|
-
echo ""
|
|
82
|
-
echo "========================================"
|
|
83
|
-
echo " 参数配置"
|
|
84
|
-
echo "========================================"
|
|
85
|
-
|
|
86
|
-
printf "起始端口 (--base-port) [默认: 9222]: "
|
|
87
|
-
read INPUT_BASE_PORT
|
|
88
|
-
BASE_PORT="${INPUT_BASE_PORT:-9222}"
|
|
89
|
-
|
|
90
|
-
printf "端口数量 (--port-count) [默认: 10]: "
|
|
91
|
-
read INPUT_PORT_COUNT
|
|
92
|
-
PORT_COUNT="${INPUT_PORT_COUNT:-10}"
|
|
93
|
-
|
|
94
|
-
printf "任务国家 (--job-locations) [默认: 无,使用全部]: "
|
|
95
|
-
read INPUT_JOB_LOCATIONS
|
|
96
|
-
|
|
97
|
-
# ---------- 4. 获取配置中的用户编号并拼接 ----------
|
|
98
|
-
CONFIG_USER_ID=""
|
|
99
|
-
if [ -f "$CONFIG_PATH" ]; then
|
|
100
|
-
CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
|
|
101
|
-
fi
|
|
102
|
-
if [ -z "$CONFIG_USER_ID" ]; then
|
|
103
|
-
CONFIG_USER_ID="user"
|
|
104
|
-
fi
|
|
105
|
-
USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
|
|
106
|
-
|
|
107
|
-
echo ""
|
|
108
|
-
echo "========================================"
|
|
109
|
-
echo " 启动 tt-help explore"
|
|
110
|
-
echo "========================================"
|
|
111
|
-
echo " 用户编号: $USER_ID"
|
|
112
|
-
echo " 起始端口: $BASE_PORT"
|
|
113
|
-
echo " 端口数量: $PORT_COUNT"
|
|
114
|
-
if [ -n "$INPUT_JOB_LOCATIONS" ]; then echo " 任务国家: $INPUT_JOB_LOCATIONS"; fi
|
|
115
|
-
echo " 最大关注: 5"
|
|
116
|
-
echo " 最大粉丝: 5"
|
|
117
|
-
echo " 速度: stealth (最慢)"
|
|
118
|
-
echo "========================================"
|
|
119
|
-
JOB_LOC_ARGS=""
|
|
120
|
-
if [ -n "$INPUT_JOB_LOCATIONS" ]; then JOB_LOC_ARGS="--job-locations $INPUT_JOB_LOCATIONS"; fi
|
|
121
|
-
tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT" --max-following 5 --max-followers 5 $JOB_LOC_ARGS
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
PACKAGENAME="tt-help-cli-ycl"
|
|
4
|
+
CONFIG_PATH="$HOME/.tt-help.json"
|
|
5
|
+
|
|
6
|
+
echo "========================================"
|
|
7
|
+
echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
|
|
8
|
+
echo "========================================"
|
|
9
|
+
|
|
10
|
+
# ---------- 0. 根据本机 IP 自动选择 server ----------
|
|
11
|
+
LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
|
|
12
|
+
|
|
13
|
+
echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
|
|
14
|
+
|
|
15
|
+
if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
|
|
16
|
+
TARGET_SERVER="http://172.18.154.201:3001"
|
|
17
|
+
echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
|
|
18
|
+
else
|
|
19
|
+
TARGET_SERVER="http://117.71.53.99:17301"
|
|
20
|
+
echo "[提示] 未检测到内网 IP,使用公网 server"
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# ---------- 1. 检查/安装最新版本 ----------
|
|
24
|
+
LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
|
|
25
|
+
|
|
26
|
+
if [ -z "$LATEST_VERSION" ]; then
|
|
27
|
+
echo "[错误] 无法从 npm 获取最新版本信息"
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
|
|
32
|
+
|
|
33
|
+
if [ -z "$INSTALLED_VERSION" ]; then
|
|
34
|
+
echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
|
|
35
|
+
npm install -g "$PACKAGENAME"
|
|
36
|
+
if [ $? -eq 0 ]; then
|
|
37
|
+
echo "[OK] 安装完成: $LATEST_VERSION"
|
|
38
|
+
else
|
|
39
|
+
echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
|
|
43
|
+
echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
|
|
44
|
+
else
|
|
45
|
+
echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
|
|
46
|
+
echo "[执行] 正在升级最新版本..."
|
|
47
|
+
npm install -g "$PACKAGENAME" 2>/dev/null
|
|
48
|
+
if [ $? -eq 0 ]; then
|
|
49
|
+
echo "[OK] 安装完成: $LATEST_VERSION"
|
|
50
|
+
else
|
|
51
|
+
echo "[警告] 自动安装失败,尝试手动更新..."
|
|
52
|
+
npm update -g "$PACKAGENAME"
|
|
53
|
+
fi
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
# ---------- 2. 检查/设置 server 配置 ----------
|
|
57
|
+
CURRENT_SERVER=""
|
|
58
|
+
if [ -f "$CONFIG_PATH" ]; then
|
|
59
|
+
CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
|
|
63
|
+
echo "[OK] Server 配置正确: $TARGET_SERVER"
|
|
64
|
+
else
|
|
65
|
+
echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
|
|
66
|
+
echo "[执行] 正在设置 server 配置..."
|
|
67
|
+
node -e "
|
|
68
|
+
const fs = require('fs');
|
|
69
|
+
const path = require('path');
|
|
70
|
+
const configPath = path.join(require('os').homedir(), '.tt-help.json');
|
|
71
|
+
let cfg = {};
|
|
72
|
+
try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
|
|
73
|
+
cfg.server = '$TARGET_SERVER';
|
|
74
|
+
fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
|
|
75
|
+
console.log(' 已写入: ' + configPath);
|
|
76
|
+
"
|
|
77
|
+
echo "[OK] Server 配置已设置"
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
# ---------- 3. 询问用户参数 ----------
|
|
81
|
+
echo ""
|
|
82
|
+
echo "========================================"
|
|
83
|
+
echo " 参数配置"
|
|
84
|
+
echo "========================================"
|
|
85
|
+
|
|
86
|
+
printf "起始端口 (--base-port) [默认: 9222]: "
|
|
87
|
+
read INPUT_BASE_PORT
|
|
88
|
+
BASE_PORT="${INPUT_BASE_PORT:-9222}"
|
|
89
|
+
|
|
90
|
+
printf "端口数量 (--port-count) [默认: 10]: "
|
|
91
|
+
read INPUT_PORT_COUNT
|
|
92
|
+
PORT_COUNT="${INPUT_PORT_COUNT:-10}"
|
|
93
|
+
|
|
94
|
+
printf "任务国家 (--job-locations) [默认: 无,使用全部]: "
|
|
95
|
+
read INPUT_JOB_LOCATIONS
|
|
96
|
+
|
|
97
|
+
# ---------- 4. 获取配置中的用户编号并拼接 ----------
|
|
98
|
+
CONFIG_USER_ID=""
|
|
99
|
+
if [ -f "$CONFIG_PATH" ]; then
|
|
100
|
+
CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
|
|
101
|
+
fi
|
|
102
|
+
if [ -z "$CONFIG_USER_ID" ]; then
|
|
103
|
+
CONFIG_USER_ID="user"
|
|
104
|
+
fi
|
|
105
|
+
USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
|
|
106
|
+
|
|
107
|
+
echo ""
|
|
108
|
+
echo "========================================"
|
|
109
|
+
echo " 启动 tt-help explore"
|
|
110
|
+
echo "========================================"
|
|
111
|
+
echo " 用户编号: $USER_ID"
|
|
112
|
+
echo " 起始端口: $BASE_PORT"
|
|
113
|
+
echo " 端口数量: $PORT_COUNT"
|
|
114
|
+
if [ -n "$INPUT_JOB_LOCATIONS" ]; then echo " 任务国家: $INPUT_JOB_LOCATIONS"; fi
|
|
115
|
+
echo " 最大关注: 5"
|
|
116
|
+
echo " 最大粉丝: 5"
|
|
117
|
+
echo " 速度: stealth (最慢)"
|
|
118
|
+
echo "========================================"
|
|
119
|
+
JOB_LOC_ARGS=""
|
|
120
|
+
if [ -n "$INPUT_JOB_LOCATIONS" ]; then JOB_LOC_ARGS="--job-locations $INPUT_JOB_LOCATIONS"; fi
|
|
121
|
+
tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT" --max-following 5 --max-followers 5 $JOB_LOC_ARGS
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
|
|
3
|
+
const URL = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
|
|
7
|
+
const page = browser.contexts()[0].pages()[0];
|
|
8
|
+
|
|
9
|
+
// 测试 detectCaptcha
|
|
10
|
+
console.error('=== 测试 detectCaptcha (无验证码) ===');
|
|
11
|
+
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
12
|
+
await page.waitForTimeout(3000);
|
|
13
|
+
|
|
14
|
+
const { detectCaptcha, closeCaptcha, handleCaptcha } = await import('../src/scraper/modules/captcha-handler.mjs');
|
|
15
|
+
|
|
16
|
+
const r1 = await detectCaptcha(page);
|
|
17
|
+
console.error('未点击评论:', JSON.stringify(r1));
|
|
18
|
+
|
|
19
|
+
// 点击评论触发验证码
|
|
20
|
+
await page.evaluate(() => {
|
|
21
|
+
const all = document.querySelectorAll('button');
|
|
22
|
+
for (const el of all) {
|
|
23
|
+
if (/^评论$/.test(el.textContent?.trim()) && el.offsetParent !== null && el.getBoundingClientRect().width > 0) {
|
|
24
|
+
el.click();
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
await page.waitForTimeout(3000);
|
|
30
|
+
|
|
31
|
+
console.error('\n=== 测试 detectCaptcha (有验证码) ===');
|
|
32
|
+
const r2 = await detectCaptcha(page);
|
|
33
|
+
console.error('点击评论后:', JSON.stringify(r2));
|
|
34
|
+
|
|
35
|
+
console.error('\n=== 测试 closeCaptcha ===');
|
|
36
|
+
const r3 = await closeCaptcha(page);
|
|
37
|
+
await page.waitForTimeout(1000);
|
|
38
|
+
console.error('关闭结果:', JSON.stringify(r3));
|
|
39
|
+
|
|
40
|
+
const r4 = await detectCaptcha(page);
|
|
41
|
+
console.error('关闭后检测:', JSON.stringify(r4));
|
|
42
|
+
|
|
43
|
+
console.error('\n=== 测试 handleCaptcha (完整流程) ===');
|
|
44
|
+
// 重新触发
|
|
45
|
+
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
46
|
+
await page.waitForTimeout(3000);
|
|
47
|
+
await page.evaluate(() => {
|
|
48
|
+
const all = document.querySelectorAll('button');
|
|
49
|
+
for (const el of all) {
|
|
50
|
+
if (/^评论$/.test(el.textContent?.trim()) && el.offsetParent !== null && el.getBoundingClientRect().width > 0) {
|
|
51
|
+
el.click();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
await page.waitForTimeout(3000);
|
|
57
|
+
|
|
58
|
+
const r5 = await handleCaptcha(page);
|
|
59
|
+
console.error('handleCaptcha 结果:', JSON.stringify(r5));
|
|
60
|
+
|
|
61
|
+
await page.screenshot({ path: '/tmp/lib-test-final.png' });
|
|
62
|
+
console.error('\n最终截图: /tmp/lib-test-final.png');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch(err => {
|
|
66
|
+
console.error('错误:', err);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ensureBrowserReady } from '../src/lib/browser/cdp.js';
|
|
2
|
+
|
|
3
|
+
const url = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const browser = await ensureBrowserReady();
|
|
7
|
+
const defaultContext = browser.contexts()[0];
|
|
8
|
+
const pages = defaultContext.pages();
|
|
9
|
+
const page = pages[0] || await defaultContext.newPage();
|
|
10
|
+
|
|
11
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
12
|
+
await page.waitForTimeout(5000);
|
|
13
|
+
|
|
14
|
+
// 用 force: true 点击评论按钮
|
|
15
|
+
const clicked = await page.evaluate(() => {
|
|
16
|
+
const btn = document.querySelector('[data-e2e="comments"]');
|
|
17
|
+
if (btn && btn.getBoundingClientRect().width > 0) {
|
|
18
|
+
btn.click();
|
|
19
|
+
return { success: true, rect: btn.getBoundingClientRect() };
|
|
20
|
+
}
|
|
21
|
+
return { success: false };
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
console.error('点击结果:', JSON.stringify(clicked));
|
|
25
|
+
|
|
26
|
+
// 等待可能的验证码
|
|
27
|
+
await page.waitForTimeout(5000);
|
|
28
|
+
|
|
29
|
+
// 截图
|
|
30
|
+
await page.screenshot({ path: '/tmp/tiktok-comment-clicked.png' });
|
|
31
|
+
console.error('截图: /tmp/tiktok-comment-clicked.png');
|
|
32
|
+
|
|
33
|
+
// 全面检测验证码
|
|
34
|
+
const captcha = await page.evaluate(() => {
|
|
35
|
+
const result = {};
|
|
36
|
+
|
|
37
|
+
// 大尺寸 Verify 元素
|
|
38
|
+
const verifyEls = Array.from(document.querySelectorAll('[class*="Verify"], [class*="verify"]'));
|
|
39
|
+
result.verifyElements = verifyEls.filter(el => {
|
|
40
|
+
const r = el.getBoundingClientRect();
|
|
41
|
+
return r.width > 100 && r.height > 100 && el.offsetParent !== null;
|
|
42
|
+
}).map(el => ({
|
|
43
|
+
class: el.className.substring(0, 200),
|
|
44
|
+
text: el.textContent?.substring(0, 300),
|
|
45
|
+
rect: { w: Math.round(el.getBoundingClientRect().width), h: Math.round(el.getBoundingClientRect().height), x: Math.round(el.getBoundingClientRect().x), y: Math.round(el.getBoundingClientRect().y) }
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
// 全屏遮罩
|
|
49
|
+
result.fullScreenOverlays = Array.from(document.querySelectorAll('div')).filter(d => {
|
|
50
|
+
const r = d.getBoundingClientRect();
|
|
51
|
+
const style = window.getComputedStyle(d);
|
|
52
|
+
return r.width > 500 && r.height > 500 && parseInt(style.zIndex) > 900 && d.offsetParent !== null;
|
|
53
|
+
}).map(d => ({
|
|
54
|
+
class: d.className.substring(0, 100),
|
|
55
|
+
zIndex: window.getComputedStyle(d).zIndex,
|
|
56
|
+
rect: { w: Math.round(d.getBoundingClientRect().width), h: Math.round(d.getBoundingClientRect().height) }
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
result.iframes = Array.from(document.querySelectorAll('iframe')).map(f => ({
|
|
60
|
+
src: (f.src || f.getAttribute('src') || '').substring(0, 300)
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
return result;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.error('\n=== 验证码检测 ===');
|
|
67
|
+
console.error(JSON.stringify(captcha, null, 2));
|
|
68
|
+
|
|
69
|
+
if (captcha.verifyElements.length > 0 || captcha.fullScreenOverlays.length > 0 || captcha.iframes.length > 0) {
|
|
70
|
+
console.error('\n⚠️ 检测到验证码或遮罩层!');
|
|
71
|
+
} else {
|
|
72
|
+
console.error('\n✅ 未检测到验证码');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await browser.close();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
main().catch(err => {
|
|
79
|
+
console.error('错误:', err);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
import { detectCaptcha, closeCaptcha, handleCaptcha, getIncognitoPage } from '../src/scraper/modules/captcha-handler.mjs';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
|
|
6
|
+
const url = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
|
|
7
|
+
|
|
8
|
+
// 测试1: 无痕模式打开 + 点击评论
|
|
9
|
+
console.error('=== 测试: 无痕模式 ===');
|
|
10
|
+
const { page, context } = await getIncognitoPage(browser, url);
|
|
11
|
+
console.error('URL:', page.url());
|
|
12
|
+
|
|
13
|
+
await page.evaluate(() => {
|
|
14
|
+
const all = document.querySelectorAll('button');
|
|
15
|
+
for (const el of all) {
|
|
16
|
+
if (/^评论$/.test(el.textContent?.trim()) && el.offsetParent !== null && el.getBoundingClientRect().width > 0) {
|
|
17
|
+
el.click();
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
23
|
+
|
|
24
|
+
const captcha = await detectCaptcha(page);
|
|
25
|
+
console.error('验证码:', captcha);
|
|
26
|
+
|
|
27
|
+
await page.screenshot({ path: '/tmp/incognito-lib-test.png' });
|
|
28
|
+
console.error('截图: /tmp/incognito-lib-test.png');
|
|
29
|
+
|
|
30
|
+
await context.close();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
main().catch(err => {
|
|
34
|
+
console.error('错误:', err);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ensureBrowserReady } from '../src/lib/browser/cdp.js';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const browser = await ensureBrowserReady();
|
|
5
|
+
const defaultContext = browser.contexts()[0];
|
|
6
|
+
const page = defaultContext.pages()[0] || await defaultContext.newPage();
|
|
7
|
+
|
|
8
|
+
// 确保在 tiktok 页面
|
|
9
|
+
if (!page.url().includes('tiktok.com')) {
|
|
10
|
+
console.error('当前不在 TikTok 页面:', page.url());
|
|
11
|
+
await page.goto('https://www.tiktok.com', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
12
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
console.error('当前 URL:', page.url());
|
|
16
|
+
|
|
17
|
+
// 1. 检测现有 isLoggedIn 的逻辑
|
|
18
|
+
const currentUserMenu = await page.evaluate(() => {
|
|
19
|
+
const selectors = [
|
|
20
|
+
'[class*="UserMenu"]',
|
|
21
|
+
'[class*="user-menu"]',
|
|
22
|
+
'[class*="CurrentUserInfo"]',
|
|
23
|
+
];
|
|
24
|
+
const results = {};
|
|
25
|
+
for (const sel of selectors) {
|
|
26
|
+
const el = document.querySelector(sel);
|
|
27
|
+
results[sel] = !!el;
|
|
28
|
+
if (el) {
|
|
29
|
+
results[sel + '_class'] = el.className;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.error('\n=== 当前选择器检测结果 ===');
|
|
36
|
+
console.error(JSON.stringify(currentUserMenu, null, 2));
|
|
37
|
+
|
|
38
|
+
const hasLoginButton = await page.evaluate(() => {
|
|
39
|
+
const buttons = Array.from(document.querySelectorAll('button, [role="button"]'));
|
|
40
|
+
const loginButtons = buttons.filter(el =>
|
|
41
|
+
/^(登录|Log in|Sign in)$/i.test(el.textContent.trim())
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
total: buttons.length,
|
|
45
|
+
loginCount: loginButtons.length,
|
|
46
|
+
samples: loginButtons.slice(0, 5).map(el => ({
|
|
47
|
+
text: el.textContent.trim(),
|
|
48
|
+
class: el.className,
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.error('\n=== 登录按钮检测 ===');
|
|
54
|
+
console.error(JSON.stringify(hasLoginButton, null, 2));
|
|
55
|
+
|
|
56
|
+
// 2. 用更宽泛的方式找用户相关元素
|
|
57
|
+
const broadSearch = await page.evaluate(() => {
|
|
58
|
+
const allClasses = [];
|
|
59
|
+
|
|
60
|
+
// 搜索可能的用户头像/菜单元素
|
|
61
|
+
const candidates = [];
|
|
62
|
+
|
|
63
|
+
// 顶部导航区域
|
|
64
|
+
const navArea = document.querySelector('[class*="nav"], [class*="Header"], [class*="header"]');
|
|
65
|
+
if (navArea) {
|
|
66
|
+
const avatars = navArea.querySelectorAll('[class*="avatar"], [class*="Avatar"], [class*="photo"], [class*="Photo"], [class*="image"], [class*="Image"]');
|
|
67
|
+
avatars.forEach(el => {
|
|
68
|
+
candidates.push({
|
|
69
|
+
tag: el.tagName,
|
|
70
|
+
class: el.className.substring(0, 200),
|
|
71
|
+
text: el.textContent?.substring(0, 50),
|
|
72
|
+
parent: el.parentElement?.className?.substring(0, 100),
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 搜索包含用户信息的链接
|
|
78
|
+
const profileLinks = Array.from(document.querySelectorAll('a[href*="/@"]'));
|
|
79
|
+
const profileSamples = profileLinks.slice(0, 10).map(el => ({
|
|
80
|
+
href: el.href,
|
|
81
|
+
class: el.className?.substring(0, 100),
|
|
82
|
+
text: el.textContent?.substring(0, 50),
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
// 搜索所有包含 User 关键字的类名
|
|
86
|
+
const userElements = Array.from(document.querySelectorAll('*')).filter(el =>
|
|
87
|
+
el.className && typeof el.className === 'string' &&
|
|
88
|
+
/User|user|Profile|profile/.test(el.className) &&
|
|
89
|
+
el.tagName !== 'STYLE' && el.tagName !== 'SCRIPT'
|
|
90
|
+
).slice(0, 30).map(el => ({
|
|
91
|
+
tag: el.tagName,
|
|
92
|
+
class: el.className.substring(0, 150),
|
|
93
|
+
text: el.textContent?.substring(0, 30),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
navAreaFound: !!navArea,
|
|
98
|
+
avatarCandidates: candidates,
|
|
99
|
+
profileLinks: profileSamples,
|
|
100
|
+
userElements,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
console.error('\n=== 宽泛搜索 ===');
|
|
105
|
+
console.error(JSON.stringify(broadSearch, null, 2));
|
|
106
|
+
|
|
107
|
+
// 3. 截图
|
|
108
|
+
await page.screenshot({ path: '/tmp/login-debug.png' });
|
|
109
|
+
console.error('\n截图已保存到 /tmp/login-debug.png');
|
|
110
|
+
|
|
111
|
+
// 4. 汇总判断
|
|
112
|
+
const isLoggedIn = currentUserMenu['[class*="UserMenu"]'] ||
|
|
113
|
+
currentUserMenu['[class*="user-menu"]'] ||
|
|
114
|
+
currentUserMenu['[class*="CurrentUserInfo"]'] ||
|
|
115
|
+
broadSearch.userElements.length > 0;
|
|
116
|
+
|
|
117
|
+
console.error('\n=== 结论 ===');
|
|
118
|
+
console.error('isLoggedIn 函数返回:', !!(currentUserMenu['[class*="UserMenu"]'] || currentUserMenu['[class*="user-menu"]'] || currentUserMenu['[class*="CurrentUserInfo"]']) && !hasLoginButton.loginCount);
|
|
119
|
+
console.error('宽泛搜索是否找到用户元素:', broadSearch.userElements.length > 0);
|
|
120
|
+
console.error('找到用户相关元素数量:', broadSearch.userElements.length);
|
|
121
|
+
console.error('头像候选数量:', broadSearch.avatarCandidates.length);
|
|
122
|
+
console.error('Profile 链接数量:', broadSearch.profileLinks.length);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
main().catch(err => {
|
|
126
|
+
console.error('错误:', err);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
import { safeClickComment, detectCaptcha } from '../src/scraper/modules/captcha-handler.mjs';
|
|
3
|
+
import { ensureBrowserReady } from '../src/lib/browser/cdp.js';
|
|
4
|
+
|
|
5
|
+
const URL = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const browser = await ensureBrowserReady();
|
|
9
|
+
const defaultContext = browser.contexts()[0];
|
|
10
|
+
const page = defaultContext.pages()[0] || await defaultContext.newPage();
|
|
11
|
+
|
|
12
|
+
for (let i = 1; i <= 3; i++) {
|
|
13
|
+
console.error(`\n===== 第 ${i} 轮 =====`);
|
|
14
|
+
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
15
|
+
await new Promise(r => setTimeout(r, 5000));
|
|
16
|
+
|
|
17
|
+
const result = await safeClickComment(page);
|
|
18
|
+
console.error('结果:', JSON.stringify(result));
|
|
19
|
+
|
|
20
|
+
const stillThere = await detectCaptcha(page);
|
|
21
|
+
console.error('验证码残留:', !!stillThere);
|
|
22
|
+
|
|
23
|
+
await page.screenshot({ path: `/tmp/safe-click-run-${i}.png` });
|
|
24
|
+
|
|
25
|
+
// 关闭评论面板
|
|
26
|
+
await page.evaluate(() => {
|
|
27
|
+
const rightPanel = document.querySelector('[class*="RightPanelContainer"]');
|
|
28
|
+
if (rightPanel) {
|
|
29
|
+
const tabContainer = rightPanel.querySelector('[class*="TabContainer"]');
|
|
30
|
+
if (tabContainer) {
|
|
31
|
+
const closeOverlay = tabContainer.querySelector('div:last-child');
|
|
32
|
+
if (closeOverlay) closeOverlay.click();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.error('\n完成');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main().catch(err => {
|
|
43
|
+
console.error('错误:', err);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
});
|