tt-help-cli-ycl 1.4.32 → 1.4.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/src/cli/explore.js +6 -0
- package/src/cli/refresh.js +6 -0
- package/src/scraper/explore-core.js +7 -0
package/package.json
CHANGED
package/src/cli/explore.js
CHANGED
|
@@ -220,6 +220,9 @@ export async function handleExplore(options) {
|
|
|
220
220
|
browser = newBrowser;
|
|
221
221
|
const newPage = await setupNewPage(browser);
|
|
222
222
|
Object.assign(page, newPage);
|
|
223
|
+
// 重建商品页(旧 browser 已关闭)
|
|
224
|
+
await shopPage.close().catch(() => {});
|
|
225
|
+
Object.assign(shopPage, await newBrowser.contexts()[0].newPage());
|
|
223
226
|
Object.assign(cdpOptions, {
|
|
224
227
|
port: nextAccount.port,
|
|
225
228
|
userDataDir: nextAccount.userDataDir,
|
|
@@ -387,6 +390,9 @@ export async function handleExplore(options) {
|
|
|
387
390
|
browser = newBrowser;
|
|
388
391
|
const newPage = await setupNewPage(browser);
|
|
389
392
|
Object.assign(page, newPage);
|
|
393
|
+
// 重建商品页
|
|
394
|
+
await shopPage.close().catch(() => {});
|
|
395
|
+
Object.assign(shopPage, await newBrowser.contexts()[0].newPage());
|
|
390
396
|
// 重试当前用户
|
|
391
397
|
result = await processExplore(
|
|
392
398
|
page,
|
package/src/cli/refresh.js
CHANGED
|
@@ -221,6 +221,9 @@ export async function handleRefresh(options) {
|
|
|
221
221
|
browser = newBrowser;
|
|
222
222
|
const newPage = await setupNewPage(browser);
|
|
223
223
|
Object.assign(page, newPage);
|
|
224
|
+
// 重建商品页(旧 browser 已关闭)
|
|
225
|
+
await shopPage.close().catch(() => {});
|
|
226
|
+
Object.assign(shopPage, await newBrowser.contexts()[0].newPage());
|
|
224
227
|
Object.assign(cdpOptions, {
|
|
225
228
|
port: nextAccount.port,
|
|
226
229
|
userDataDir: nextAccount.userDataDir,
|
|
@@ -399,6 +402,9 @@ export async function handleRefresh(options) {
|
|
|
399
402
|
browser = newBrowser;
|
|
400
403
|
const newPage = await setupNewPage(browser);
|
|
401
404
|
Object.assign(page, newPage);
|
|
405
|
+
// 重建商品页
|
|
406
|
+
await shopPage.close().catch(() => {});
|
|
407
|
+
Object.assign(shopPage, await newBrowser.contexts()[0].newPage());
|
|
402
408
|
result = await processExplore(
|
|
403
409
|
page,
|
|
404
410
|
username,
|
|
@@ -131,6 +131,13 @@ async function processExplore(page, username, options, log) {
|
|
|
131
131
|
// 如果有商品链接,抓取商品详情页(评分、销量等)
|
|
132
132
|
if (topVideo.seoUrl && options.shopPage) {
|
|
133
133
|
try {
|
|
134
|
+
// 检查 shopPage 是否被关闭(浏览器切换账号等),尝试恢复
|
|
135
|
+
if (options.shopPage.isClosed()) {
|
|
136
|
+
const ctx = page.context();
|
|
137
|
+
options.shopPage = await ctx.newPage();
|
|
138
|
+
log(` [商品页] 已恢复 shopPage`);
|
|
139
|
+
}
|
|
140
|
+
|
|
134
141
|
const { getProductInfoCDP } = await import("../lib/shop-scraper.mjs");
|
|
135
142
|
const shopUrl = topVideo.seoUrl.replace(
|
|
136
143
|
"www.tiktok.com/shop/pdp",
|