// 拉取全部视频单篇数据(56条),输出可分析表 import { connect, evaluate, saveJson } from './lib.mjs'; import fs from 'node:fs'; 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')); const { sessionId } = await cdp.send('Target.attachToTarget', { targetId: page.targetId, flatten: true }); await cdp.send('Runtime.enable', {}, sessionId); const res = await evaluate(cdp, sessionId, `(async () => { const all = []; for (let p = 1; p <= 3; p++) { const url = '/author/eco/statistics/articleListStatistic?start_day=20261001&end_day=20261109&type=video&num=' + p + '&count=50'; const r = await fetch(url, { credentials: 'include' }); const j = await r.json(); const list = (j.data && j.data.list) || []; all.push(...list); if (list.length < 50) break; } return all; })()`); saveJson('out/videos.json', res); fs.writeFileSync('out/videos-count.txt', String(res.length), 'utf8'); console.log('VIDEOS=' + res.length); if (res.length) console.log('FIELDS=' + Object.keys(res[0]).join(',')); process.exit(0);