import { attach } from '/tmp/cdp3.mjs'; import fs from 'fs'; const wait = ms => new Promise(z => setTimeout(z, ms)); const c = await attach('/web/temu/add') || await attach('dianxiaomi.com'); const all = new Set(); for (let i=0;i<80;i++){ const got = await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop(); if(!dd)return'[]'; return JSON.stringify([...dd.querySelectorAll('.ant-select-item-option')].map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim()).filter(Boolean));})()`); const arr=JSON.parse(String(got)); const before=all.size; arr.forEach(x=>all.add(x)); const sc = await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop(); if(!dd)return 0; const rc=dd.querySelector('.rc-virtual-list-holder')||dd; rc.scrollTop=rc.scrollTop+600; return rc.scrollTop;})()`); await wait(400); if (all.size===before && i>4 && Number(sc)===0) break; } const list=[...all]; fs.writeFileSync('/tmp/temu_cats.json', JSON.stringify(list,null,1)); console.log('Temu 类目数:', list.length); list.forEach((x,i)=>console.log(` ${String(i).padStart(3)} ${x}`)); process.exit(0);