From a22f1a42e4983a502a05045d18d6279e178b2e53 Mon Sep 17 00:00:00 2001 From: zhu <1812073942@qq.com> Date: Wed, 6 May 2026 17:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE+=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=88=AC=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/domScraper.ts | 20 ++++++++++- src/config/platforms.ts | 68 ++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/background/domScraper.ts b/src/background/domScraper.ts index 985fc9e..7714c8a 100644 --- a/src/background/domScraper.ts +++ b/src/background/domScraper.ts @@ -1,5 +1,23 @@ import type {PlatformFieldConfig} from '@/types'; +/** + * 等待重试机制 + */ +async function waitForElement(rootDom: ParentNode, selector: string) { + let retryCount = 5; + for (let i = 0; i < retryCount; i++) { + const element = rootDom.querySelector(selector); + if (element) { + return element; + } + if (i < retryCount) { + await sleep(500); + } + } + return null; +} + + // 睡眠工具,给点击、翻页、异步渲染留出等待时间。 const sleep = (ms?: number) => new Promise((resolve) => window.setTimeout(resolve, ms ?? 1500)); @@ -54,7 +72,7 @@ export async function processFields(columns: PlatformFieldConfig[], rootDom: Ele for (const item of columns) { await autoClick(item, rootDom); - const element = rootDom.querySelector(item.className); + const element = await waitForElement(rootDom, item.className) if (!element) { result[item.label] = '没找到该元素'; diff --git a/src/config/platforms.ts b/src/config/platforms.ts index f60bc0f..34d0867 100644 --- a/src/config/platforms.ts +++ b/src/config/platforms.ts @@ -1,5 +1,4 @@ - -import type { PlatformConfig } from '@/types'; +import type {PlatformConfig} from '@/types'; export const PLATFORM_CONFIGS: PlatformConfig[] = [ { @@ -36,46 +35,46 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [ }, { label: "商业分析", - className: ".data-dashboard-async-data-wrapper .custom-row", + className: ".data-dashboard .metrics", keys: [ { label: "销售", - className: ".custom-col-5:nth-child(1) ", + className: ".metric:nth-child(1) ", keys: [ - { label: "value", className: ".dashboard-item-value" }, - { label: "change", className: ".dashboard-item-rate-number" } + {label: "value", className: ".metric-value"}, + {label: "change", className: ".metric-rate"} ] }, { label: "访客数", - className: ".custom-col-5:nth-child(2) ", + className: ".metric:nth-child(2) ", keys: [ - { label: "value", className: ".dashboard-item-value" }, - { label: "change", className: ".dashboard-item-rate-number" } + {label: "value", className: ".metric-value"}, + {label: "change", className: ".metric-rate"} ] }, { label: "Product Clicks", - className: ".custom-col-5:nth-child(3)", + className: ".metric:nth-child(3)", keys: [ - { label: "value", className: ".dashboard-item-value" }, - { label: "change", className: ".dashboard-item-rate-number" } + {label: "value", className: ".metric-value"}, + {label: "change", className: ".metric-rate"} ] }, { label: "订单", - className: ".custom-col-5:nth-child(4)", + className: ".metric:nth-child(4)", keys: [ - { label: "value", className: ".dashboard-item-value" }, - { label: "change", className: ".dashboard-item-rate-number" } + {label: "value", className: ".metric-value"}, + {label: "change", className: ".metric-rate"} ] }, { label: "Order Conversion Rate", - className: ".custom-col-5:nth-child(5)", + className: ".metric:nth-child(5)", keys: [ - { label: "value", className: ".dashboard-item-value" }, - { label: "change", className: ".dashboard-item-rate-number" } + {label: "value", className: ".metric-value"}, + {label: "change", className: ".metric-rate"} ] }, ] @@ -88,31 +87,31 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [ label: "广告余额", className: ".ads-data-cell:nth-of-type(1) ", keys: [ - { label: "value", className: ".ads-data-report-number" }, + {label: "value", className: ".ads-data-report-number"}, ] }, { label: "销售额", className: ".ads-data-cell:nth-child(3) ", keys: [ - { label: "value", className: ".ads-data-report-number" }, - { label: "change", className: ".ratio " } + {label: "value", className: ".ads-data-report-number"}, + {label: "change", className: ".ratio "} ] }, { label: "花费", className: ".ads-data-cell:nth-child(4)", keys: [ - { label: "value", className: ".ads-data-report-number" }, - { label: "change", className: ".ratio " } + {label: "value", className: ".ads-data-report-number"}, + {label: "change", className: ".ratio "} ] }, { label: "广告支出回报率", className: ".ads-data-cell:nth-child(5)", keys: [ - { label: "value", className: ".ads-data-report-number" }, - { label: "change", className: ".ratio " } + {label: "value", className: ".ads-data-report-number"}, + {label: "change", className: ".ratio "} ] }, ] @@ -144,9 +143,13 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [ label: "进行中广告列表", className: ".eds-table__body-container", type: 2, + condition: { + list: [".eds-radio-group label:nth-child(3)"], + time: 400 + }, tableParts: [ - { name: "fixed", select: ".eds-table__fix-body" }, - { name: "main", select: ".eds-table__main-body" } + {name: "fixed", select: ".eds-table__fix-body"}, + {name: "main", select: ".eds-table__main-body"} ], keys: [ { @@ -207,21 +210,12 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [ { name: "评论管理", uniqueKey: "message", - url: "https://seller.shopee.com.my/portal/settings/shop/rating", + url: "https://seller.shopee.com.my/portal/settings/shop/rating?pageNumber=1&fromPageNumber=1&cursor=0&pageSize=20&replied=TO_REPLY&ratingStar=2&ratingStar=1", checkSelector: '.page-container', fields: [ { label: "低星评论", className: ".border-solid.rounded", - condition: { - list: [ - ".flex.items-center.mt-6 div:nth-child(3)", - ".eds-react-checkbox-group label:nth-child(2)", - ".eds-react-checkbox-group label:nth-child(3)", - ".eds-react-checkbox-group label:nth-child(4)" - ], - time: 200, - }, type: 1, keys: [ {