import { newTarget, CDP } from '/tmp/cdp3.mjs'; import fs from 'fs'; const wait = ms => new Promise(z => setTimeout(z, ms)); const SHOP = process.argv[2] || '①Shein-武汉九个网-箱包'; const tl = await (await fetch('http://127.0.0.1:9223/json/list')).json(); for (const t of tl.filter(x=>x.type==='page'&&/shein/i.test(x.url))) await fetch(`http://127.0.0.1:9223/json/close/${t.id}`).catch(()=>{}); await wait(1200); const t = await newTarget('about:blank'); const c = await CDP.connect(t.webSocketDebuggerUrl); await c.send('Page.enable'); await c.send('Runtime.enable'); await c.send('Page.navigate',{url:'https://www.dianxiaomi.com/web/sheinProduct/add'}); await wait(22000); // 选店铺 const pos = JSON.parse(String(await c.evalJS(`(()=>{const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null) .find(x=>{const l=x.querySelector('label'); return l&&/店铺/.test(l.innerText||'');}); const s=(it||document).querySelector('.ant-select-selector'); if(!s)return'[]'; s.scrollIntoView({block:'center'}); const r=s.getBoundingClientRect(); return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`))); for (const type of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type,x:pos[0],y:pos[1],button:'left',clickCount:1}); await wait(2500); const pk = await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop(); if(!dd)return'no-dd'; const hit=[...dd.querySelectorAll('.ant-select-item-option')].find(o=>(o.innerText||'').trim()===${JSON.stringify(SHOP)}); if(!hit)return'no-hit'; for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'ok';})()`); console.log('选店铺:', pk, SHOP); await wait(9000); const o = await c.evalJS(`(()=>{ const p=document.querySelector('#app').__vue_app__.config.globalProperties.$pinia; const stores=[...p._s.keys()].filter(k=>/shein/i.test(k)); const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).map(x=>{ const l=x.querySelector('label'); const lab=l?(l.innerText||'').replace(/\\s+/g,' ').trim():''; const req=!!x.querySelector('.ant-form-item-required'); const inp=x.querySelector('input:not([type=hidden])'); const ta=x.querySelector('textarea'); const sel=x.querySelector('.ant-select-selection-item'); return (req?'* ':' ')+lab.slice(0,26).padEnd(27)+'['+(ta?'ta':(sel?'select':(inp?'input':'-')))+'] '+(sel?sel.innerText.trim():(inp?inp.value:(ta?ta.value:''))).slice(0,26); }).filter(x=>x.trim().length>4); const dump={}; for(const n of stores){ try{ const s=p._s.get(n).$state; const o2={}; for(const k of Object.keys(s)){ const v=s[k]; if(v===null||['string','number','boolean'].includes(typeof v)){ if(v!==''&&v!==null&&String(v).length<55) o2[k]=String(v); } else if(v&&typeof v==='object'&&!Array.isArray(v)){ for(const k2 of Object.keys(v)){ const v2=v[k2]; if(v2===null||['string','number','boolean'].includes(typeof v2)){ if(v2!==''&&v2!==null&&String(v2).length<45) o2[k+'.'+k2]=String(v2); } } } } dump[n]=o2; }catch(e){ dump[n]='ERR'; } } return JSON.stringify({stores, items, dump},null,1);})()`); fs.writeFileSync('/tmp/shein_map.json', String(o)); const j=JSON.parse(String(o)); console.log('stores:', j.stores.join(', ')); console.log('--- form ---'); j.items.forEach(x=>console.log(' '+x)); console.log('--- store 关键字段 ---'); for(const [n,v] of Object.entries(j.dump)){ const hit=Object.entries(v||{}).filter(([k])=>/shop|site|currency|cat|brand|price|weight/i.test(k)); if(hit.length) console.log(' ##',n,hit.map(([k,val])=>k+'='+val).join(' | ').slice(0,320)); } process.exit(0);