This commit is contained in:
rsgltzyd 2024-07-25 23:16:20 +08:00
parent 1d6b5ab207
commit 241c39523b
5 changed files with 23 additions and 22 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
node_modules/
*.png
businessData.json
data/user.json

View File

@ -2,12 +2,12 @@ import { launch } from 'puppeteer';
import fs from 'fs';
import 'dotenv/config.js'
import { setLocalStorage } from './utils/userUtils.js';
import { getDate } from './businessDataUtil.js';
import { getDate, cleanType } from './utils/businessDataUtil.js';
(async () => {
const browser = await launch({ headless: true, args: [`--window-size=1920,1080`], defaultViewport: { width: 1920, height: 1080 } });
const browser = await launch({ headless: false, args: [`--window-size=1920,1080`], defaultViewport: { width: 1920, height: 1080 } });
const page = await browser.newPage();
setLocalStorage(page, 'user.json');
setLocalStorage(page, '.\\data\\user.json');
await page.goto('https://dev-dmp.meiguanjia.net/report/businessData');
await page.waitForSelector('.menu-list-second');
@ -17,25 +17,23 @@ import { getDate } from './businessDataUtil.js';
const str = await page.evaluate(node => node.textContent.trim(), childElements[1]);
console.log(str);
const file = 'businessData.json';//获取file
const file = './data/businessData.json';
fs.writeFileSync(file, '', 'utf-8');
await getDate(page, fs);
console.log('========');
const time = await page.$('.arco-picker-start-time');
await time.click({ clickCount: 3 });
await time.type('2024-06', { delay: 100 });
await getDate(page, fs);
await getDate(page, fs, file);
console.log('========');
await time.click({ clickCount: 3 });
await time.type('2024-05', { delay: 100 });
await getDate(page, fs);
await cleanType(page, '.arco-picker-start-time', '2024-06');
await getDate(page, fs, file);
console.log('========');
await time.click({ clickCount: 3 });
await time.type('2024-04', { delay: 100 });
await getDate(page, fs);
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);
console.log('========');
await browser.close();

View File

@ -18,7 +18,7 @@ import 'dotenv/config.js';
const localStorage = await page.evaluate(() => Object.assign({}, window.localStorage));
const importStorage = JSON.stringify(localStorage);
const file = 'user.json';//获取file
const file = './data/user.json';
fs.writeFileSync(file, importStorage, 'utf-8');
await browser.close();
})();

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
export async function getDate(page, fs) {
export async function getDate(page, fs, file) {
await new Promise(r => setTimeout(r, 2000));
await page.waitForSelector('.ai_custome');
const aiCustome = await page.$$('.ai_custome .ai_custome_item .amount');
@ -9,7 +9,6 @@ export async function getDate(page, fs) {
}
let importStorage = '\n' + JSON.stringify(Array.from(ai)) + '\n';
const file = 'businessData.json';//获取file
fs.appendFileSync(file, importStorage, 'utf-8');
const elementHandle = await page.waitForSelector('.bi_warp iframe');
@ -26,8 +25,12 @@ export async function getDate(page, fs) {
console.log('#label-content not found in the iframe');
}
importStorage = '\n' + JSON.stringify(Array.from(its)) + '\n';
importStorage = JSON.stringify(Array.from(its)) + '\n';
fs.appendFileSync(file, importStorage, 'utf-8');
}
// console.log(its);
export async function cleanType(page, element, timeContent) {
const time = await page.$(element);
await time.click({ clickCount: 3 });
await time.type(timeContent, { delay: 100 });
}