// 点击"单篇数据"tab,抓作品级明细 import { connect, evaluate, saveJson } from './lib.mjs'; const cdp = await connect(); const { targetInfos } = await cdp.send('Target.getTargets'); const page = targetInfos.find(t => t.type === 'page' && t.url.includes('baijiahao.baidu.com')); if (!page) { console.log('NO_PAGE'); process.exit(1); } const { sessionId } = await cdp.send('Target.attachToTarget', { targetId: page.targetId, flatten: true }); await cdp.send('Runtime.enable', {}, sessionId); // 清空并点击单篇数据 tab const clicked = await evaluate(cdp, sessionId, `(() => { if (window.__CAP) window.__CAP.length = 0; const nodes = Array.from(document.querySelectorAll('*')).filter(e => e.children.length === 0 && (e.innerText || '').trim() === '单篇数据'); if (nodes.length) { nodes[0].click(); return 'clicked:' + nodes.length; } return 'not found'; })()`); console.log('CLICK=' + clicked); await new Promise(r => setTimeout(r, 8000)); const cap = await evaluate(cdp, sessionId, `(window.__CAP||[]).map(x=>({url:x.url, body:x.body}))`); saveJson('out/single-capture.json', cap); console.log('CAP=' + (cap || []).length); for (const c of cap || []) console.log('API ' + String(c.url).slice(0, 160)); process.exit(0);