Files

43 lines
3.1 KiB
JavaScript

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';
import { readFileSync } from 'fs';
const pid='676236596821';
const it = JSON.parse(readFileSync('/home/admin9webs/tiktok建品/tk_input.json','utf8'))[pid];
const c = await newPage('https://www.dianxiaomi.com/web/smtChoice/add');
await wait(12000);
// 店 + 备货类型(照抄 try1 的两步)
for (const [label, hint] of [['店铺名称','店铺'],['备货类型','备货']]) {
const p = JSON.parse(String(await c.evalJS(`(()=>{const f=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>new RegExp(${JSON.stringify(label)}).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)]);})()`)));
if(!p.length) { console.log(hint,'没找到'); continue; }
await c.send('Input.dispatchMouseEvent',{type:'mouseMoved',x:p[0],y:p[1],buttons:0}); await wait(300);
for(const t of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type:t,x:p[0],y:p[1],button:'left',clickCount:1,buttons:1});
await wait(2000);
console.log(hint,'选中:', String(await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
if(!dd) return 'no-dd'; const op=[...dd.querySelectorAll('.ant-select-item-option')][0]; if(!op) return 'no-op';
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 (op.innerText||'').trim();})()`)));
await wait(label==='店铺名称'?6000:3000);
}
console.log('类目:', S(String(await selectCategory(c, it.cat_kw||'发夹', it.cat_kw))).slice(0,90));
await wait(6000);
const d = await c.evalJS(`(()=>{
const want=['品牌','高关注化学品','产地'];
const out=[];
for (const e of document.querySelectorAll('.ant-form-item')) {
if (e.offsetParent===null) continue;
const l=e.querySelector('label'); const t=l?(l.innerText||'').replace(/\\s+/g,' ').trim():'';
if(!want.some(w=>t.startsWith(w)||t.startsWith('*'+w))) continue;
const sel=e.querySelector('.ant-select');
out.push({ txt:t.slice(0,30), labelCls:l?String(l.className).slice(0,60):'', labelHTML:l?l.outerHTML.replace(/\\s+/g,' ').slice(0,150):'',
hasAttrLabel:!!e.querySelector('.attr-label'), attrCls:String((e.querySelector('.attr-label')||{}).className||''),
selTxt: sel?(sel.innerText||'').replace(/\\s+/g,' ').trim().slice(0,20):'no-sel',
nested: !!e.parentElement.closest('.ant-form-item') });
}
return JSON.stringify(out);})()`);
console.log('必填属性项:', JSON.stringify(JSON.parse(String(d)), null, 1).slice(0,2000));
await closePage(c); process.exit(0);