修改配置+优化爬取

This commit is contained in:
zhu
2026-05-06 17:42:40 +08:00
parent 7e2a83efd6
commit a22f1a42e4
2 changed files with 50 additions and 38 deletions

View File

@@ -1,5 +1,23 @@
import type {PlatformFieldConfig} from '@/types'; 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)); 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) { for (const item of columns) {
await autoClick(item, rootDom); await autoClick(item, rootDom);
const element = rootDom.querySelector(item.className); const element = await waitForElement(rootDom, item.className)
if (!element) { if (!element) {
result[item.label] = '没找到该元素'; result[item.label] = '没找到该元素';

View File

@@ -1,5 +1,4 @@
import type {PlatformConfig} from '@/types';
import type { PlatformConfig } from '@/types';
export const PLATFORM_CONFIGS: PlatformConfig[] = [ export const PLATFORM_CONFIGS: PlatformConfig[] = [
{ {
@@ -36,46 +35,46 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
}, },
{ {
label: "商业分析", label: "商业分析",
className: ".data-dashboard-async-data-wrapper .custom-row", className: ".data-dashboard .metrics",
keys: [ keys: [
{ {
label: "销售", label: "销售",
className: ".custom-col-5:nth-child(1) ", className: ".metric:nth-child(1) ",
keys: [ keys: [
{ label: "value", className: ".dashboard-item-value" }, {label: "value", className: ".metric-value"},
{ label: "change", className: ".dashboard-item-rate-number" } {label: "change", className: ".metric-rate"}
] ]
}, },
{ {
label: "访客数", label: "访客数",
className: ".custom-col-5:nth-child(2) ", className: ".metric:nth-child(2) ",
keys: [ keys: [
{ label: "value", className: ".dashboard-item-value" }, {label: "value", className: ".metric-value"},
{ label: "change", className: ".dashboard-item-rate-number" } {label: "change", className: ".metric-rate"}
] ]
}, },
{ {
label: "Product Clicks", label: "Product Clicks",
className: ".custom-col-5:nth-child(3)", className: ".metric:nth-child(3)",
keys: [ keys: [
{ label: "value", className: ".dashboard-item-value" }, {label: "value", className: ".metric-value"},
{ label: "change", className: ".dashboard-item-rate-number" } {label: "change", className: ".metric-rate"}
] ]
}, },
{ {
label: "订单", label: "订单",
className: ".custom-col-5:nth-child(4)", className: ".metric:nth-child(4)",
keys: [ keys: [
{ label: "value", className: ".dashboard-item-value" }, {label: "value", className: ".metric-value"},
{ label: "change", className: ".dashboard-item-rate-number" } {label: "change", className: ".metric-rate"}
] ]
}, },
{ {
label: "Order Conversion Rate", label: "Order Conversion Rate",
className: ".custom-col-5:nth-child(5)", className: ".metric:nth-child(5)",
keys: [ keys: [
{ label: "value", className: ".dashboard-item-value" }, {label: "value", className: ".metric-value"},
{ label: "change", className: ".dashboard-item-rate-number" } {label: "change", className: ".metric-rate"}
] ]
}, },
] ]
@@ -144,6 +143,10 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
label: "进行中广告列表", label: "进行中广告列表",
className: ".eds-table__body-container", className: ".eds-table__body-container",
type: 2, type: 2,
condition: {
list: [".eds-radio-group label:nth-child(3)"],
time: 400
},
tableParts: [ tableParts: [
{name: "fixed", select: ".eds-table__fix-body"}, {name: "fixed", select: ".eds-table__fix-body"},
{name: "main", select: ".eds-table__main-body"} {name: "main", select: ".eds-table__main-body"}
@@ -207,21 +210,12 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
{ {
name: "评论管理", name: "评论管理",
uniqueKey: "message", 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', checkSelector: '.page-container',
fields: [ fields: [
{ {
label: "低星评论", label: "低星评论",
className: ".border-solid.rounded", 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, type: 1,
keys: [ keys: [
{ {