tt-help-cli-ycl 1.4.49 → 1.4.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/package.json +1 -1
- package/src/lib/shop-scraper.mjs +0 -63
package/package.json
CHANGED
package/src/lib/shop-scraper.mjs
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { ProxyAgent, request } from "undici";
|
|
20
|
-
import { execSync } from "child_process";
|
|
21
20
|
import { DEFAULT_PROXY } from "./constants.js";
|
|
22
21
|
|
|
23
22
|
const PDP_HEADERS = {
|
|
@@ -81,62 +80,6 @@ function extractJsonByKey(html, keyPattern) {
|
|
|
81
80
|
return null;
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
/**
|
|
85
|
-
* Windows: 后台服务的 Playwright 浏览器在 Session 0(隔离桌面),
|
|
86
|
-
* RDP 看不到。改为用 start 命令推到交互桌面,然后轮询 undici 等 IP 恢复信用。
|
|
87
|
-
*/
|
|
88
|
-
async function resolveCaptchaWindows(url, proxyUrl) {
|
|
89
|
-
// 用 Windows start 命令在交互桌面打开 Edge
|
|
90
|
-
const edgeUrl = url.replace("shop.tiktok.com", "www.tiktok.com/shop/pdp");
|
|
91
|
-
try {
|
|
92
|
-
execSync(`start "" "microsoft-edge:${edgeUrl}"`, {
|
|
93
|
-
shell: "cmd.exe",
|
|
94
|
-
timeout: 5000,
|
|
95
|
-
});
|
|
96
|
-
console.error(
|
|
97
|
-
"[shop-scraper] Windows: 已用 start 命令在交互桌面打开 Edge,请在 RDP 中完成验证码",
|
|
98
|
-
);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
console.error("[shop-scraper] Windows: start 命令失败:", e.message);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 轮询 undici 等待 IP 信用恢复(用户解完验证码后代理 IP 就有信用了)
|
|
104
|
-
const proxy = proxyUrl || DEFAULT_PROXY;
|
|
105
|
-
const agent = proxy ? new ProxyAgent(proxy) : null;
|
|
106
|
-
const POLL_MS = 5000;
|
|
107
|
-
const MAX_WAIT_MS = 3600_000; // 最长等 1 小时
|
|
108
|
-
const start = Date.now();
|
|
109
|
-
|
|
110
|
-
while (Date.now() - start < MAX_WAIT_MS) {
|
|
111
|
-
await new Promise((r) => setTimeout(r, POLL_MS));
|
|
112
|
-
try {
|
|
113
|
-
const { body } = await request(url, {
|
|
114
|
-
headers: PDP_HEADERS,
|
|
115
|
-
...(agent ? { dispatcher: agent } : {}),
|
|
116
|
-
});
|
|
117
|
-
const html = await body.text();
|
|
118
|
-
if (
|
|
119
|
-
html.includes('"product_model"') ||
|
|
120
|
-
html.includes('"review_ratings"')
|
|
121
|
-
) {
|
|
122
|
-
console.error("[shop-scraper] Captcha solved, IP credit restored");
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
} catch {
|
|
126
|
-
// 继续轮询
|
|
127
|
-
}
|
|
128
|
-
// 每 60 秒打印一次状态
|
|
129
|
-
if (Math.round((Date.now() - start) / 60000) % 5 === 0) {
|
|
130
|
-
console.error(
|
|
131
|
-
`[shop-scraper] 等待验证码解决中... 已等待 ${Math.round((Date.now() - start) / 60000)} 分钟`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
console.error("[shop-scraper] Windows: 等待验证码超时");
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
83
|
/**
|
|
141
84
|
* Open a headed browser for manual captcha solving, extract cookies
|
|
142
85
|
* so undici can reuse them for a while.
|
|
@@ -147,12 +90,6 @@ async function resolveCaptchaWindows(url, proxyUrl) {
|
|
|
147
90
|
export async function resolveCaptchaWithBrowser(url, proxyUrl) {
|
|
148
91
|
const { chromium } = await import("playwright");
|
|
149
92
|
|
|
150
|
-
// Windows 后台服务启动的浏览器在 Session 0,RDP 看不到。
|
|
151
|
-
// 用 start 命令推到当前交互桌面。
|
|
152
|
-
if (process.platform === "win32") {
|
|
153
|
-
return resolveCaptchaWindows(url, proxyUrl);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
93
|
const args = ["--no-sandbox"];
|
|
157
94
|
if (proxyUrl) {
|
|
158
95
|
args.push(`--proxy-server=${proxyUrl.replace("http://", "http://")}`);
|