fix
This commit is contained in:
parent
468a252f21
commit
9a9b4646ca
15
example2.js
15
example2.js
@ -18,24 +18,13 @@ import { getDate, cleanType, changeTimeDimension } from './utils/businessDataUti
|
|||||||
const str = await page.evaluate(node => node.textContent.trim(), childElements[1]);
|
const str = await page.evaluate(node => node.textContent.trim(), childElements[1]);
|
||||||
console.log(str);
|
console.log(str);
|
||||||
|
|
||||||
await changeTimeDimension(page, '周报');
|
// await changeTimeDimension(page, '周报');
|
||||||
|
|
||||||
const file = './data/businessData.json';
|
const file = './data/businessData.json';
|
||||||
|
|
||||||
fs.writeFileSync(file, '', 'utf-8');
|
fs.writeFileSync(file, '', 'utf-8');
|
||||||
|
|
||||||
await getDate(page, fs, file);
|
await cleanType(page, '.arco-picker-start-time', '2024-07');
|
||||||
console.log('========');
|
|
||||||
|
|
||||||
await cleanType(page, '.arco-picker-start-time', '2024-06');
|
|
||||||
await getDate(page, fs, file);
|
|
||||||
console.log('========');
|
|
||||||
|
|
||||||
await cleanType(page, '.arco-picker-start-time', '2024-05');
|
|
||||||
await getDate(page, fs, file);
|
|
||||||
console.log('========');
|
|
||||||
|
|
||||||
await cleanType(page, '.arco-picker-start-time', '2024-04');
|
|
||||||
await getDate(page, fs, file);
|
await getDate(page, fs, file);
|
||||||
console.log('========');
|
console.log('========');
|
||||||
|
|
||||||
|
|||||||
@ -1,31 +1,41 @@
|
|||||||
export async function getDate(page, fs, file) {
|
export async function getDate(page, fs, file) {
|
||||||
|
const its = new Map();
|
||||||
|
|
||||||
await new Promise(r => setTimeout(r, 2000));
|
await new Promise(r => setTimeout(r, 2000));
|
||||||
await page.waitForSelector('.ai_custome');
|
await page.waitForSelector('.ai_custome');
|
||||||
const aiCustome = await page.$$('.ai_custome .ai_custome_item .amount');
|
const aiCustome = await page.$$('.ai_custome .ai_custome_item');
|
||||||
let ai = new Set();
|
|
||||||
for (const e of aiCustome) {
|
|
||||||
let str = await page.evaluate(element => element.textContent, e);
|
|
||||||
ai.add(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
let importStorage = '\n' + JSON.stringify(Array.from(ai), null, 2) + '\n';
|
if (aiCustome.length > 0) {
|
||||||
fs.appendFileSync(file, importStorage, 'utf-8');
|
for (const iterator of aiCustome) {
|
||||||
|
const key = await iterator.$('span');
|
||||||
|
const value = await iterator.$('div');
|
||||||
|
const keyStr = await page.evaluate(element => element.textContent.trim(), key);
|
||||||
|
const valueStr = await page.evaluate(element => element.textContent.trim(), value);
|
||||||
|
its.set(keyStr, valueStr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('.ai_custome_item not found');
|
||||||
|
}
|
||||||
|
|
||||||
const elementHandle = await page.waitForSelector('.bi_warp iframe');
|
const elementHandle = await page.waitForSelector('.bi_warp iframe');
|
||||||
const frame = await elementHandle.contentFrame();
|
const frame = await elementHandle.contentFrame();
|
||||||
await frame.waitForSelector('#label-content');
|
await frame.waitForSelector('#label-content');
|
||||||
const items = await frame.$$('#label-content'); // Use $$ to get all matching elements
|
const items = await frame.$$('#label-content');
|
||||||
let its = new Set();
|
|
||||||
if (items.length > 0) { // Check if items array is not empty
|
if (items.length > 0) {
|
||||||
for (const e of items) {
|
for (const e of items) {
|
||||||
let str = await frame.evaluate(element => element.textContent, e); // Use frame.evaluate() here
|
const key = await e.$('span p');
|
||||||
its.add(str.replace(/\s+/g, ' '));
|
const value = await e.$('span span');
|
||||||
|
const keyStr = await frame.evaluate(element => element.textContent.trim(), key);
|
||||||
|
const valueStr = await frame.evaluate(element => element.textContent.trim(), value);
|
||||||
|
|
||||||
|
its.set(keyStr, valueStr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('#label-content not found in the iframe');
|
console.log('#label-content not found in the iframe');
|
||||||
}
|
}
|
||||||
|
|
||||||
importStorage = JSON.stringify(Array.from(its), null, 2) + '\n';
|
const importStorage = JSON.stringify(Array.from(its), null, 2);
|
||||||
fs.appendFileSync(file, importStorage, 'utf-8');
|
fs.appendFileSync(file, importStorage, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,21 +45,29 @@ export async function cleanType(page, element, timeContent) {
|
|||||||
await time.type(timeContent, { delay: 100 });
|
await time.type(timeContent, { delay: 100 });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changeTimeDimension(page, timeDimension) {
|
/**
|
||||||
|
*
|
||||||
|
* @param {Page} page
|
||||||
|
* @param {Number} dismensionNumber
|
||||||
|
*/
|
||||||
|
export async function changeTimeDimension(page, dismensionNumber) {
|
||||||
|
const timeDimension = [
|
||||||
|
'日报',
|
||||||
|
'周报',
|
||||||
|
'月报',
|
||||||
|
'自定义'
|
||||||
|
];
|
||||||
|
|
||||||
let rb = await page.$('.arco-space-item .arco-select-view-value');
|
let rb = await page.$('.arco-space-item .arco-select-view-value');
|
||||||
let s = await page.evaluate(node => node.textContent.trim(), rb);
|
let s = await page.evaluate(node => node.textContent.trim(), rb);
|
||||||
console.log(s);
|
|
||||||
|
|
||||||
await rb.click();
|
await rb.click();
|
||||||
const timeMap = new Map();
|
const timeMap = new Map();
|
||||||
rb = await page.$$('.arco-select-dropdown-list .arco-select-option');
|
rb = await page.$$('.arco-select-dropdown-list .arco-select-option');
|
||||||
for (const iterator of rb) {
|
for (const iterator of rb) {
|
||||||
s = await page.evaluate(node => node.textContent.trim(), iterator)
|
s = await page.evaluate(node => node.textContent.trim(), iterator)
|
||||||
console.log(s);
|
|
||||||
timeMap.set(s, iterator);
|
timeMap.set(s, iterator);
|
||||||
}
|
}
|
||||||
console.log('===');
|
|
||||||
console.log(timeMap);
|
|
||||||
|
|
||||||
await timeMap.get(timeDimension).click();
|
await timeMap.get(timeDimension[dismensionNumber]).click();
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user