const { chromium } = require('playwright-core'); const PROFILE = 'C:\\Users\\wxy\\AppData\\Local\\LTJT-ERP-Hermes-Chrome'; const CHROME = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'; const ORDERS_URL = 'https://ltjt.yunzhi.run/System/Business/orders.asp'; const DATE = '2026-8-4'; async function main() { const context = await chromium.launchPersistentContext(PROFILE, { executablePath: CHROME, headless: false, viewport: { width: 1440, height: 900 }, }); const page = context.pages()[0] || await context.newPage(); try { await page.goto(ORDERS_URL, { waitUntil: 'domcontentloaded', timeout: 60000 }); await page.waitForTimeout(3000); const loginInput = await page.$('input[name="UserName"]'); if (loginInput) { console.log(JSON.stringify({ status: 'login_required' })); return; } await page.locator('input[name="riqi"][value="chufari"]').check().catch(() => {}); await page.waitForTimeout(800); await page.locator('#S_chufariqi').fill(DATE); await page.locator('#S_chufarizhi').fill(DATE); await page.waitForTimeout(300); await page.locator('#SearchButton').click(); await page.waitForTimeout(6000); const rows = await page.evaluate(() => { return Array.from(document.querySelectorAll('tr')).map(tr => ({ text: tr.innerText.replace(/\s+/g, ' ').trim(), links: Array.from(tr.querySelectorAll('a')).map(a => ({ text: a.innerText, href: a.getAttribute('href') || '', onclick: a.getAttribute('onclick') || '' })) })); }); const candidates = rows.filter(r => (r.text.includes('LLW') || r.text.includes('LW-') || r.text.includes('遇见')) && r.links.some(l => l.onclick.includes('OPEN_update')) ); if (candidates.length === 0) { console.log(JSON.stringify({ status: 'not_found', date: DATE })); } else { for (const r of candidates) { const modify = r.links.find(l => l.onclick.includes('OPEN_update')); const ddid = modify ? (modify.onclick.match(/OPEN_update\('([^']+)'/) || [])[1] : null; const groupMatch = r.text.match(/(LLW|LW)-\d{6}[A-Z]-[A-Z]/); console.log(JSON.stringify({ groupNo: groupMatch ? groupMatch[0] : null, ddid: ddid || null, preview: r.text.slice(0, 300), })); } } } catch (err) { console.log(JSON.stringify({ status: 'error', message: err.message })); } finally { await context.close(); } } main();