diff --git a/src/main/process/runTaskOperationService.ts b/src/main/process/runTaskOperationService.ts index 63160d4..408b77e 100644 --- a/src/main/process/runTaskOperationService.ts +++ b/src/main/process/runTaskOperationService.ts @@ -42,13 +42,15 @@ export function runTaskOperationService() { }) 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}`) const result = await executeScriptServiceInstance.executeScript(item.scriptPath, { roomType: roomType[item.channel], startTime: options.startTime, endTime: options.endTime, operation: options.operation, + tabIndex: i, }) results.push({ channel: item.channel, diff --git a/src/main/scripts/fg_trace.mjs b/src/main/scripts/fg_trace.mjs index f840390..630bc7d 100644 --- a/src/main/scripts/fg_trace.mjs +++ b/src/main/scripts/fg_trace.mjs @@ -91,10 +91,9 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope }; (async () => { - let browser; + const browser = await chromium.connectOverCDP('http://127.0.0.1:9222'); try { - browser = await chromium.connectOverCDP(`http://127.0.0.1:9222`); const context = browser.contexts()[0]; await context.addInitScript(() => { @@ -102,8 +101,8 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope }); const pages = await context.pages(); - - const page = pages.length ? pages[0] : await context.newPage(); + const tabIndex = Number(process.env.TAB_INDEX); + const page = pages.length ? pages[tabIndex] : await context.newPage(); await page.goto('https://hotel.fliggy.com/ebooking/hotelBaseInfoUv.htm#/ebk/homeV1'); diff --git a/src/main/scripts/mt.md b/src/main/scripts/mt.md new file mode 100644 index 0000000..103ba1f --- /dev/null +++ b/src/main/scripts/mt.md @@ -0,0 +1,3 @@ +```html +
第29届安团家博会-贵阳展将至,请提前调整好03月20日至03月22日房价,确保房量和房态准确,并及时安排好接单人员查看其他热点
~
周二
02.03
周三
02.04
周四
02.05
周五
02.06
周六
02.07
周日
02.08
周一
02.09
周二
02.10
周三
02.11
周四
02.12
周五
02.13
周六
02.14
操作
尊享豪华大床房(私汤)
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
至尊养生汤屋(私汤)
3/0/0
3/0/0
3/0/0
2/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
2/0/0
亲子房
3/0/0
2/0/1
2/0/1
19/0/0
3/0/0
3/0/0
3/0/0
2/0/1
2/0/1
0/0/3
3/0/0
19/0/0
榻榻米双床房
1/0/2
10/0/3
10/0/0
10/0/1
10/0/2
9/0/1
6/0/4
8/0/4
8/0/2
8/0/2
8/0/2
10/0/0
豪华至尊养生汤屋(私汤)
不限/0/1
不限/0/0
不限/0/0
3/0/1
不限/0/0
不限/0/0
不限/0/0
不限/0/0
不限/0/0
不限/0/0
不限/0/0
0/0/0
亲子太空舱
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
1/0/0
行政套房A
2/0/1
2/0/1
3/0/0
7/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
7/0/0
汤墅会馆(私汤)
3/0/0
3/0/0
3/0/0
1/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
1/0/0
至尊大床房
3/0/0
3/0/0
3/0/0
1/0/0
2/0/1
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
1/0/0
高级标准间
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
豪华特色房
3/0/0
3/0/0
3/0/0
21/0/0
2/0/1
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
20/0/0
豪华套房(私汤)
3/0/0
3/0/0
3/0/0
2/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
2/0/0
太空舱(私汤)
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
3/0/0
1/0/2
2/0/1
3/0/0
暂无数据
暂无可查看的房型/产品,请尝试其他搜索/筛选条件,或联系业务经理
暂无数据
暂无可查看的房型/产品,请尝试其他搜索/筛选条件,或联系业务经理
正在加载中
+``` \ No newline at end of file diff --git a/src/main/scripts/mt.png b/src/main/scripts/mt.png new file mode 100644 index 0000000..f411c96 Binary files /dev/null and b/src/main/scripts/mt.png differ diff --git a/src/main/scripts/mt_trace.mjs b/src/main/scripts/mt_trace.mjs index 4404af1..5979e18 100644 --- a/src/main/scripts/mt_trace.mjs +++ b/src/main/scripts/mt_trace.mjs @@ -1,4 +1,48 @@ +import { chromium } from 'playwright'; import log from 'electron-log'; -log.info('mt_trace.mjs placeholder: not implemented'); -process.exit(0); +const getOrCreateTab = async (context, targetIndex) => { + 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 {} + } + } +})(); diff --git a/src/main/service/execute-script-service/index.ts b/src/main/service/execute-script-service/index.ts index 17df8ae..a3d48c8 100644 --- a/src/main/service/execute-script-service/index.ts +++ b/src/main/service/execute-script-service/index.ts @@ -22,6 +22,7 @@ export class executeScriptService extends EventEmitter { const startTime = options?.startTime ?? ''; const endTime = options?.endTime ?? ''; const operation = options?.operation ?? ''; + const tabIndex = options?.tabIndex ?? ''; const child = spawn('node', [scriptPath], { env: { @@ -29,7 +30,8 @@ export class executeScriptService extends EventEmitter { ROOM_TYPE: String(roomType), START_DATE: String(startTime), END_DATE: String(endTime), - OPERATION: String(operation) + OPERATION: String(operation), + TAB_INDEX: String(tabIndex), }, });