import { chromium } from 'playwright'; const b = await chromium.launch(); const p = await b.newPage({ viewport: { width: 390, height: 844 } }); await p.goto('http://localhost:3212/news', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(3000); const links = await p.locator('a[href*="/news/"]').evaluateAll(a => a.map(x => ({ href: x.getAttribute('href'), text: x.textContent.trim().slice(0, 30), inFooter: !!x.closest('footer'), inHeader: !!x.closest('header')}))); console.log('全部 /news/ 链接:', JSON.stringify(links)); await p.locator('button', { hasText: '公司新闻' }).first().click(); await p.waitForTimeout(1200); const after = await p.locator('a[href*="/news/"]').evaluateAll(a => a.map(x => ({ href: x.getAttribute('href'), text: x.textContent.trim().slice(0, 24), inFooter: !!x.closest('footer'), inHeader: !!x.closest('header')}))); console.log('筛选后:', JSON.stringify(after)); await b.close();