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