fix
This commit is contained in:
parent
1d6b5ab207
commit
241c39523b
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*.png
|
*.png
|
||||||
businessData.json
|
businessData.json
|
||||||
|
data/user.json
|
||||||
|
|||||||
30
example2.js
30
example2.js
@ -2,12 +2,12 @@ import { launch } from 'puppeteer';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import 'dotenv/config.js'
|
import 'dotenv/config.js'
|
||||||
import { setLocalStorage } from './utils/userUtils.js';
|
import { setLocalStorage } from './utils/userUtils.js';
|
||||||
import { getDate } from './businessDataUtil.js';
|
import { getDate, cleanType } from './utils/businessDataUtil.js';
|
||||||
|
|
||||||
(async () => {
|
(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();
|
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.goto('https://dev-dmp.meiguanjia.net/report/businessData');
|
||||||
|
|
||||||
await page.waitForSelector('.menu-list-second');
|
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]);
|
const str = await page.evaluate(node => node.textContent.trim(), childElements[1]);
|
||||||
console.log(str);
|
console.log(str);
|
||||||
|
|
||||||
const file = 'businessData.json';//获取file
|
const file = './data/businessData.json';
|
||||||
|
|
||||||
fs.writeFileSync(file, '', 'utf-8');
|
fs.writeFileSync(file, '', 'utf-8');
|
||||||
|
|
||||||
await getDate(page, fs);
|
await getDate(page, fs, file);
|
||||||
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);
|
|
||||||
console.log('========');
|
console.log('========');
|
||||||
|
|
||||||
await time.click({ clickCount: 3 });
|
await cleanType(page, '.arco-picker-start-time', '2024-06');
|
||||||
await time.type('2024-05', { delay: 100 });
|
await getDate(page, fs, file);
|
||||||
await getDate(page, fs);
|
|
||||||
console.log('========');
|
console.log('========');
|
||||||
|
|
||||||
await time.click({ clickCount: 3 });
|
await cleanType(page, '.arco-picker-start-time', '2024-05');
|
||||||
await time.type('2024-04', { delay: 100 });
|
await getDate(page, fs, file);
|
||||||
await getDate(page, fs);
|
console.log('========');
|
||||||
|
|
||||||
|
await cleanType(page, '.arco-picker-start-time', '2024-04');
|
||||||
|
await getDate(page, fs, file);
|
||||||
console.log('========');
|
console.log('========');
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|||||||
2
login.js
2
login.js
@ -18,7 +18,7 @@ import 'dotenv/config.js';
|
|||||||
const localStorage = await page.evaluate(() => Object.assign({}, window.localStorage));
|
const localStorage = await page.evaluate(() => Object.assign({}, window.localStorage));
|
||||||
|
|
||||||
const importStorage = JSON.stringify(localStorage);
|
const importStorage = JSON.stringify(localStorage);
|
||||||
const file = 'user.json';//获取file
|
const file = './data/user.json';
|
||||||
fs.writeFileSync(file, importStorage, 'utf-8');
|
fs.writeFileSync(file, importStorage, 'utf-8');
|
||||||
await browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
@ -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 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 .amount');
|
||||||
@ -9,7 +9,6 @@ export async function getDate(page, fs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let importStorage = '\n' + JSON.stringify(Array.from(ai)) + '\n';
|
let importStorage = '\n' + JSON.stringify(Array.from(ai)) + '\n';
|
||||||
const file = 'businessData.json';//获取file
|
|
||||||
fs.appendFileSync(file, importStorage, 'utf-8');
|
fs.appendFileSync(file, importStorage, 'utf-8');
|
||||||
|
|
||||||
const elementHandle = await page.waitForSelector('.bi_warp iframe');
|
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');
|
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');
|
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 });
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user