feat: 新增美团脚本
This commit is contained in:
@@ -42,13 +42,15 @@ export function runTaskOperationService() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const results: any[] = []
|
const results: any[] = []
|
||||||
for (const item of scriptPaths) {
|
for (let i = 0; i < scriptPaths.length; i++) {
|
||||||
|
const item = scriptPaths[i]
|
||||||
log.info(`Launching script for channel ${item.channel}: ${item.scriptPath}`)
|
log.info(`Launching script for channel ${item.channel}: ${item.scriptPath}`)
|
||||||
const result = await executeScriptServiceInstance.executeScript(item.scriptPath, {
|
const result = await executeScriptServiceInstance.executeScript(item.scriptPath, {
|
||||||
roomType: roomType[item.channel],
|
roomType: roomType[item.channel],
|
||||||
startTime: options.startTime,
|
startTime: options.startTime,
|
||||||
endTime: options.endTime,
|
endTime: options.endTime,
|
||||||
operation: options.operation,
|
operation: options.operation,
|
||||||
|
tabIndex: i,
|
||||||
})
|
})
|
||||||
results.push({
|
results.push({
|
||||||
channel: item.channel,
|
channel: item.channel,
|
||||||
|
|||||||
@@ -91,10 +91,9 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope
|
|||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let browser;
|
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
browser = await chromium.connectOverCDP(`http://127.0.0.1:9222`);
|
|
||||||
const context = browser.contexts()[0];
|
const context = browser.contexts()[0];
|
||||||
|
|
||||||
await context.addInitScript(() => {
|
await context.addInitScript(() => {
|
||||||
@@ -102,8 +101,8 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pages = await context.pages();
|
const pages = await context.pages();
|
||||||
|
const tabIndex = Number(process.env.TAB_INDEX);
|
||||||
const page = pages.length ? pages[0] : await context.newPage();
|
const page = pages.length ? pages[tabIndex] : await context.newPage();
|
||||||
|
|
||||||
await page.goto('https://hotel.fliggy.com/ebooking/hotelBaseInfoUv.htm#/ebk/homeV1');
|
await page.goto('https://hotel.fliggy.com/ebooking/hotelBaseInfoUv.htm#/ebk/homeV1');
|
||||||
|
|
||||||
|
|||||||
3
src/main/scripts/mt.md
Normal file
3
src/main/scripts/mt.md
Normal file
File diff suppressed because one or more lines are too long
BIN
src/main/scripts/mt.png
Normal file
BIN
src/main/scripts/mt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
@@ -1,4 +1,48 @@
|
|||||||
|
import { chromium } from 'playwright';
|
||||||
import log from 'electron-log';
|
import log from 'electron-log';
|
||||||
|
|
||||||
log.info('mt_trace.mjs placeholder: not implemented');
|
const getOrCreateTab = async (context, targetIndex) => {
|
||||||
process.exit(0);
|
const idx =
|
||||||
|
Number.isFinite(targetIndex) && targetIndex >= 0 ? Math.floor(targetIndex) : 1;
|
||||||
|
|
||||||
|
let pages = await context.pages();
|
||||||
|
while (pages.length <= idx) {
|
||||||
|
await context.newPage();
|
||||||
|
pages = await context.pages();
|
||||||
|
}
|
||||||
|
const page = pages[idx];
|
||||||
|
await page.bringToFront();
|
||||||
|
return page;
|
||||||
|
};
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const context = browser.contexts()[0];
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('No browser context available');
|
||||||
|
}
|
||||||
|
|
||||||
|
await context.addInitScript(() => {
|
||||||
|
Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
|
||||||
|
});
|
||||||
|
|
||||||
|
const tabIndex = Number(process.env.TAB_INDEX);
|
||||||
|
const page = await getOrCreateTab(context, tabIndex);
|
||||||
|
await page.goto('https://me.meituan.com/ebooking/merchant/product#/index');
|
||||||
|
} catch (error) {
|
||||||
|
log.error(error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
if (browser) {
|
||||||
|
try {
|
||||||
|
if (typeof browser.disconnect === 'function') {
|
||||||
|
await browser.disconnect();
|
||||||
|
} else {
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class executeScriptService extends EventEmitter {
|
|||||||
const startTime = options?.startTime ?? '';
|
const startTime = options?.startTime ?? '';
|
||||||
const endTime = options?.endTime ?? '';
|
const endTime = options?.endTime ?? '';
|
||||||
const operation = options?.operation ?? '';
|
const operation = options?.operation ?? '';
|
||||||
|
const tabIndex = options?.tabIndex ?? '';
|
||||||
|
|
||||||
const child = spawn('node', [scriptPath], {
|
const child = spawn('node', [scriptPath], {
|
||||||
env: {
|
env: {
|
||||||
@@ -29,7 +30,8 @@ export class executeScriptService extends EventEmitter {
|
|||||||
ROOM_TYPE: String(roomType),
|
ROOM_TYPE: String(roomType),
|
||||||
START_DATE: String(startTime),
|
START_DATE: String(startTime),
|
||||||
END_DATE: String(endTime),
|
END_DATE: String(endTime),
|
||||||
OPERATION: String(operation)
|
OPERATION: String(operation),
|
||||||
|
TAB_INDEX: String(tabIndex),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user