Files

44 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Lazada:选店 → 用英文词选类目 → dump lazada* store 与字段落点(最后一块未知) */
import { newPage, closePage, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
import { selectCategory } from '/home/admin9webs/shein建品/sh_build.mjs';
import { SAN as S } from '/tmp/cdp3.mjs';
const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`;
const c = await newPage('https://www.dianxiaomi.com/web/lazada/add');
await wait(12000);
// 选店铺(第一家 Shehoney_MY)
const pos = JSON.parse(String(await c.evalJS(`(()=>{const f=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null)
.find(e=>/店铺/.test((e.querySelector('label')||{}).innerText||''));
const s=f?f.querySelector('.ant-select-selector'):null; 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)]);})()`)));
await c.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: pos[0], y: pos[1], buttons: 0 }); await wait(300);
for (const t of ['mousePressed', 'mouseReleased'])
await c.send('Input.dispatchMouseEvent', { type: t, x: pos[0], y: pos[1], button: 'left', clickCount: 1, buttons: 1 });
await wait(2500);
await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
const op=[...dd.querySelectorAll('.ant-select-item-option')][0]; const r=op.getBoundingClientRect();
for(const ev of ['mousedown','mouseup','click']) op.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window,clientX:r.x+r.width/2,clientY:r.y+r.height/2}));
return 1;})()`);
await wait(7000);
console.log('类目:', S(String(await selectCategory(c, 'Hair Accessories', 'Hair Accessories'))).slice(0, 130));
await wait(8000);
const st = await c.evalJS(`(()=>{const p=${P};
const ids=(p._s instanceof Map?[...p._s.keys()]:Object.keys(p._s)).filter(x=>/lazada/i.test(x));
const out={};
const fmt=(v,d=0)=>{ if(v===null||v===undefined) return String(v); if(Array.isArray(v)) return '['+v.length+']'+(v[0]?JSON.stringify(v[0]).slice(0,70):'');
if(typeof v==='object'){ if(d>1) return '{...}'; const o={}; let n=0; for(const k of Object.keys(v)){o[k]=fmt(v[k],d+1); if(++n>14){o['…']='';break;}} return o;} return String(v).slice(0,40); };
for(const id of ids){ try{ const s=(p._s.get?p._s.get(id):p._s[id]).$state; out[id]= s.formState?fmt(s.formState):('keys='+Object.keys(s).slice(0,10).join(',')); }catch(e){out[id]='ERR';} }
return JSON.stringify(out);})()`);
console.log('lazada stores:', JSON.stringify(JSON.parse(String(st)), null, 1).slice(0, 1800));
const items = await c.evalJS(`JSON.stringify([...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).slice(0,20).map(e=>{
const l=e.querySelector('label'); const req=l&&/required/.test(String(l.className))?'*':'';
return req+((e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,40));}))`);
console.log('表单项:', S(String(items)).slice(0, 1100));
try { await c.shot('/tmp/lz_store.jpg'); console.log('shot ok'); } catch (e) {}
await closePage(c);
process.exit(0);