- TikTok/Shopee/速卖通/Walmart 各 46-47 条已在待发布 - Ozon 47 条已建、改价 40/47 - SHEIN 配方跑通第一条;Temu 差「预览图」一步 - 核心产出:MYJ.message.error 钩子诊断法(解开了三个平台的保存静默拦截) - 含下一轮提示词 NEXT-ROUND-PROMPT.md
63 lines
4.9 KiB
JavaScript
63 lines
4.9 KiB
JavaScript
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 CATKW = process.argv[3] || '发夹';
|
|
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(1000);
|
|
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(21000);
|
|
// 店铺
|
|
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'); 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);
|
|
await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
|
|
const hit=[...dd.querySelectorAll('.ant-select-item-option')].find(o=>(o.innerText||'').trim()===${JSON.stringify(SHOP)});
|
|
if(hit) for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 1;})()`);
|
|
await wait(8000);
|
|
// 开分类下拉并选目标
|
|
const cp = 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.querySelector('.ant-select-selector'); 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:cp[0],y:cp[1],button:'left',clickCount:1});
|
|
await wait(3500);
|
|
const pk = await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
|
|
if(!dd)return'no-dd'; const its=[...dd.querySelectorAll('.ant-select-item-option')];
|
|
const hit=its.find(o=>new RegExp('^\\\\s*'+${JSON.stringify(CATKW)}).test((o.innerText||'').trim()));
|
|
if(!hit)return'no-hit:'+its.slice(0,5).map(o=>o.innerText.trim()).join(',');
|
|
for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
|
|
return 'picked:'+(hit.innerText||'').trim();})()`);
|
|
console.log('类目:', pk);
|
|
await wait(12000);
|
|
const o = await c.evalJS(`(()=>{
|
|
const p=document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
|
|
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,24).padEnd(25)+'['+(ta?'ta':(sel?'select':(inp?'input':'-')))+'] '+(sel?sel.innerText.trim():(inp?inp.value:(ta?ta.value:''))).slice(0,22);
|
|
}).filter(x=>x.trim().length>4);
|
|
const tables=[...document.querySelectorAll('table')].filter(t=>t.offsetParent!==null).map(t=>({
|
|
th:[...t.querySelectorAll('th')].map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim()).slice(0,12),
|
|
rows:[...t.querySelectorAll('tbody tr')].filter(x=>x.querySelectorAll('input').length).length}));
|
|
const cut=(x,d=0)=>(d>3?'…':(Array.isArray(x)?(x.length?'['+x.length+'] '+JSON.stringify(x[0]).slice(0,220):'[]'):(x&&typeof x==='object'?Object.fromEntries(Object.entries(x).map(([k,v])=>[k,cut(v,d+1)])):x)));
|
|
const dump={};
|
|
for(const n of ['sheinAddProductStore','sheinSkuDataStore','sheinSkuAttrStore','sheinAddBasicStore','sheinImgStore'])
|
|
{ try{dump[n]=cut(JSON.parse(JSON.stringify(p._s.get(n).$state)));}catch(e){dump[n]='ERR';} }
|
|
return JSON.stringify({items, tables, dump},null,1);})()`);
|
|
fs.writeFileSync('/tmp/shein_deep.json', String(o));
|
|
const j=JSON.parse(String(o));
|
|
console.log('=== form ==='); j.items.forEach(x=>console.log(' '+x));
|
|
console.log('=== tables ==='); console.log(JSON.stringify(j.tables));
|
|
console.log('=== stores ===');
|
|
for(const [n,v] of Object.entries(j.dump)) console.log(' ##',n,JSON.stringify(v).slice(0,520));
|
|
process.exit(0);
|