修改配置+优化爬取
This commit is contained in:
@@ -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] = '没找到该元素';
|
||||
|
||||
@@ -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: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user