修改配置+优化爬取

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';
/**
* 等待重试机制
*/
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] = '没找到该元素';