店小秘多平台铺货配方:7 平台建品脚本 + 静默拦截诊断法 + 项目状态

- TikTok/Shopee/速卖通/Walmart 各 46-47 条已在待发布
- Ozon 47 条已建、改价 40/47
- SHEIN 配方跑通第一条;Temu 差「预览图」一步
- 核心产出:MYJ.message.error 钩子诊断法(解开了三个平台的保存静默拦截)
- 含下一轮提示词 NEXT-ROUND-PROMPT.md
This commit is contained in:
admin9webs committed 2026-09-20 17:29:38 +08:00
commit f5720ad613
94 files changed
+21561

No files matched your search

+186
View File
@@ -0,0 +1,186 @@
{
"548459586741": {
"ok": true,
"cat": "picked[0/52]:Health(保健)/Sexual Wellness(情趣用品)/Sex Toys(情趣玩具) "
},
"764423265986": {
"ok": true,
"cat": "picked[0/1]:Health(保健)/Medical Supplies(医疗保健)/Health Monitors & Tests(健康仪器与测试仪)/Thermometers(温度计) "
},
"685456757807": {
"ok": true,
"cat": "picked[0/1]:Home Appliances(家用电器)/Small Household Appliances(小型家电)/Sewing Machines & Accessories(缝纫机 & 配件) "
},
"735147938123": {
"ok": true,
"cat": "picked[1/8]:Fashion Accessories(时尚配饰)/Hair Accessories(发饰)/Hair Clips & Hair Pins(发夹) "
},
"627879474686": {
"ok": true,
"cat": "picked[0/8]:Baby & Kids Fashion(童装)/Baby & Kids Accessories(婴儿与儿童配饰)/Socks(袜子) "
},
"610164857063": {
"ok": true,
"cat": "picked[1/8]:Fashion Accessories(时尚配饰)/Hair Accessories(发饰)/Hair Clips & Hair Pins(发夹) "
},
"676236596821": {
"ok": true,
"cat": "picked[0/8]:Baby & Kids Fashion(童装)/Baby & Kids Accessories(婴儿与儿童配饰)/Hair Accessories(发饰) "
},
"708420302844": {
"ok": true,
"cat": "picked[0/3]:Automobiles(汽车类)/Automotive Keychains & Key Covers(汽车钥匙扣和钥匙套) "
},
"866537106657": {
"ok": true,
"cat": "picked[0/1]:Home Appliance (家用电器)/Small Hou ehold Appliance (小型家电)/Sewing Machine & Acce orie (缝纫机 & 配件) "
},
"547183997437": {
"ok": true,
"cat": "picked[1/3]:Fa hion Acce orie (时尚配饰)/Fine Jewelry(轻奢珠宝)/Necklace (项链) "
},
"657617635303": {
"ok": true,
"cat": "picked[0/56]:Stationery(文具)/Art Supplie (美术用品)/Acrylic Paint(亚克力颜料) "
},
"641673262387": {
"ok": true,
"cat": "picked[14/15]:Home & Living(家居生活)/Home Organizer (居家收纳)/Jewelry Organizer (首饰收纳) "
},
"953869908708": {
"ok": true,
"cat": "picked[0/8]:Automobile (汽车类)/Automobile Exterior Acce orie (车外配件)/Sticker , Logo & Emblem (车贴、车标改装) "
},
"703822717997": {
"ok": true,
"cat": "picked[0/56]:Stationery(文具)/Art Supplie (美术用品)/Acrylic Paint(亚克力颜料) "
},
"863524134410": {
"ok": true,
"cat": "picked[0/8]:Automobile (汽车类)/Automobile Exterior Acce orie (车外配件)/Sticker , Logo & Emblem (车贴、车标改装) "
},
"694637537727": {
"ok": true,
"cat": "picked[5/67]:Beauty(美妆保健)/Beauty Tool (美容工具)/Makeup Acce orie (化妆工具)/Makeup Bag & Organizer (化妆包与收纳袋) "
},
"623011262210": {
"ok": true,
"cat": "picked[0/8]:Automobile (汽车类)/Automobile Exterior Acce orie (车外配件)/Sticker , Logo & Emblem (车贴、车标改装) "
},
"836512561982": {
"ok": true,
"cat": "picked[0/1]:Beauty(美妆保健)/Beauty Tool (美容工具)/Makeup Acce orie (化妆工具)/Makeup Bag & Organizer (化妆包与收纳袋) "
},
"714492799386": {
"ok": true,
"cat": "picked[0/1]:Beauty(美妆保健)/Beauty Tool (美容工具)/Makeup Acce orie (化妆工具)/Makeup Bag & Organizer (化妆包与收纳袋) "
},
"591994902720": {
"ok": true,
"cat": "picked[0/1]:Stationery(文具)/School & Office Equipment(学校与办公用品)/Pencil Ca e (文具盒/笔袋) "
},
"853414558425": {
"ok": true,
"cat": "picked[0/3]:Automobile (汽车类)/Automotive Keychain & Key Cover (汽车钥匙扣和钥匙套) "
},
"997450831819": {
"ok": true,
"cat": "picked[0/8]:Automobile (汽车类)/Automobile Exterior Acce orie (车外配件)/Sticker , Logo & Emblem (车贴、车标改装) "
},
"639409307567": {
"ok": true,
"cat": "picked[0/1]:Home & Living(家居生活)/Decoration(装饰)/Wallpaper & Wall Sticker (墙纸与窗贴) "
},
"902440558099": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"823838532886": {
"ok": true,
"cat": "picked[0/2]:Men Bag (男包)/Wallet (钱包)/Card Holder (卡包) "
},
"698782391248": {
"ok": true,
"cat": "picked[0/8]:Automobile (汽车类)/Automobile Exterior Acce orie (车外配件)/Sticker , Logo & Emblem (车贴、车标改装) "
},
"707826905566": {
"ok": true,
"cat": "picked[1/13]:Men Bag (男包)/Wallet (钱包)/Bifold & Trifold Wallet (双折&三折钱包) "
},
"1027332215847": {
"ok": true,
"cat": "picked[0/2]:Home & Living(家居生活)/Home Organizer (居家收纳)/Shoe Storage Boxe (鞋盒) "
},
"682195499823": {
"ok": true,
"cat": "picked[0/56]:Stationery(文具)/Art Supplie (美术用品)/Acrylic Paint(亚克力颜料) "
},
"823560564174": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"739147684759": {
"ok": true,
"cat": "picked[0/1]:Home Appliance (家用电器)/Small Hou ehold Appliance (小型家电)/Sewing Machine & Acce orie (缝纫机 & 配件) "
},
"621300323670": {
"ok": true,
"cat": "picked[0/56]:Stationery(文具)/Art Supplie (美术用品)/Acrylic Paint(亚克力颜料) "
},
"896469995553": {
"ok": true,
"cat": "picked[0/3]:Automobile (汽车类)/Automotive Keychain & Key Cover (汽车钥匙扣和钥匙套) "
},
"944470567338": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"787261097583": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"833753630925": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"719391062058": {
"ok": true,
"cat": "picked[0/2]:Home & Living(家居生活)/Home Organizer (居家收纳)/Shoe Storage Boxe (鞋盒) "
},
"857781294719": {
"ok": true,
"cat": "picked[0/8]:Baby & Kid Fa hion(童装)/Baby & Kid Acce orie (婴儿与儿童配饰)/Hair Acce orie (发饰) "
},
"863384503032": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"774494945453": {
"ok": true,
"cat": "picked[0/3]:Automobile (汽车类)/Automotive Keychain & Key Cover (汽车钥匙扣和钥匙套) "
},
"750271307455": {
"ok": true,
"cat": "picked[0/3]:Automobile (汽车类)/Automotive Keychain & Key Cover (汽车钥匙扣和钥匙套) "
},
"726442972676": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"775057912118": {
"ok": true,
"cat": "picked[0/3]:Automobile (汽车类)/Automotive Keychain & Key Cover (汽车钥匙扣和钥匙套) "
},
"893592264148": {
"ok": true,
"cat": "picked[0/8]:Baby & Kid Fa hion(童装)/Baby & Kid Acce orie (婴儿与儿童配饰)/Hair Acce orie (发饰) "
},
"607330049419": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
},
"854003999648": {
"ok": true,
"cat": "picked[1/8]:Fa hion Acce orie (时尚配饰)/Hair Acce orie (发饰)/Hair Clip & Hair Pin (发夹) "
}
}
+1
View File
@@ -0,0 +1 @@
{"n":172,"items":[{"id":"184807703510036273","oid":"854003999648","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510035741","oid":"607330049419","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510035057","oid":"893592264148","shop":6142973,"title":"","cat":101029,"catPath":""},{"id":"184807703510034417","oid":"775057912118","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510033855","oid":"726442972676","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510033465","oid":"750271307455","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510033029","oid":"774494945453","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510032637","oid":"863384503032","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510032293","oid":"857781294719","shop":6142973,"title":"","cat":101029,"catPath":""},{"id":"184807703510031901","oid":"719391062058","shop":6142973,"title":"","cat":101255,"catPath":""},{"id":"184807703510031383","oid":"833753630925","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510030917","oid":"787261097583","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510030569","oid":"944470567338","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510030139","oid":"896469995553","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510029645","oid":"621300323670","shop":6142973,"title":"","cat":101365,"catPath":""},{"id":"184807703510029069","oid":"739147684759","shop":6142973,"title":"","cat":100173,"catPath":""},{"id":"184807703510028623","oid":"823560564174","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510028233","oid":"682195499823","shop":6142973,"title":"","cat":101365,"catPath":""},{"id":"184807703510027575","oid":"1027332215847","shop":6142973,"title":"","cat":101255,"catPath":""},{"id":"184807703510026781","oid":"707826905566","shop":6142973,"title":"","cat":100611,"catPath":""},{"id":"184807703510025839","oid":"698782391248","shop":6142973,"title":"","cat":101435,"catPath":""},{"id":"184807703510025179","oid":"823838532886","shop":6142973,"title":"","cat":100608,"catPath":""},{"id":"184807703510024541","oid":"902440558099","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510023971","oid":"639409307567","shop":6142973,"title":"","cat":101157,"catPath":""},{"id":"184807703510023389","oid":"997450831819","shop":6142973,"title":"","cat":101435,"catPath":""},{"id":"184807703510022689","oid":"853414558425","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510022085","oid":"591994902720","shop":6142973,"title":"","cat":101359,"catPath":""},{"id":"184807703510021797","oid":"714492799386","shop":6142973,"title":"","cat":101650,"catPath":""},{"id":"184807703510021497","oid":"836512561982","shop":6142973,"title":"","cat":101650,"catPath":""},{"id":"184807703510021291","oid":"623011262210","shop":6142973,"title":"","cat":101435,"catPath":""},{"id":"184807703510021059","oid":"694637537727","shop":6142973,"title":"","cat":101650,"catPath":""},{"id":"184807703510020731","oid":"863524134410","shop":6142973,"title":"","cat":101435,"catPath":""},{"id":"184807703510020443","oid":"703822717997","shop":6142973,"title":"","cat":101365,"catPath":""},{"id":"184807703510020027","oid":"953869908708","shop":6142973,"title":"","cat":101435,"catPath":""},{"id":"184807703510019455","oid":"641673262387","shop":6142973,"title":"","cat":101260,"catPath":""},{"id":"184807703510018695","oid":"657617635303","shop":6142973,"title":"","cat":101365,"catPath":""},{"id":"184807703510018191","oid":"547183997437","shop":6142973,"title":"","cat":102064,"catPath":""},{"id":"184807703510017925","oid":"866537106657","shop":6142973,"title":"","cat":100173,"catPath":""},{"id":"184807703510017639","oid":"708420302844","shop":6142973,"title":"","cat":100753,"catPath":""},{"id":"184807703510017247","oid":"676236596821","shop":6142973,"title":"","cat":101029,"catPath":""},{"id":"184807703510016863","oid":"610164857063","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510016495","oid":"627879474686","shop":6142973,"title":"","cat":101032,"catPath":""},{"id":"184807703510016073","oid":"735147938123","shop":6142973,"title":"","cat":100147,"catPath":""},{"id":"184807703510015731","oid":"685456757807","shop":6142973,"title":"","cat":100173,"catPath":""},{"id":"184807703510014969","oid":"764423265986","shop":6142973,"title":"","cat":100423,"catPath":""},{"id":"184807703510014619","oid":"548459586741","shop":6142973,"title":"","cat":100142,"catPath":""},{"id":"184807703510012679","oid":"661190598139","shop":6142973,"title":"","cat":101029,"catPath":""},{"id":"4810365555229229","oid":"733058615988","shop":6100336,"title":"","cat":101349,"catPath":""},{"id":"4810365430386949","oid":"693118601337","shop":3377110,"title":"","cat":101639,"catPath":""},{"id":"4810365324256099","oid":"573Line truncated
+172
View File
@@ -0,0 +1,172 @@
import { newTarget, CDP, SAN } from '/tmp/cdp3.mjs';
import fs from 'fs';
/* ── Shopee (Ljbgkj, shopId 6142973) 单件建品配方 ──
node spbatch.mjs <oid> [catKeyword]
选店铺 → 分类弹窗 → 单件 → 标题/描述 → 价格(CNY)/库存 → 重量/尺寸
→ 图片 → 来源URL → 保存 → 回读 */
const OID = process.argv[2];
const CAT_KW = process.argv[3] || '';
if (!OID) { console.log('用法: node spbatch.mjs <oid> [catKeyword]'); process.exit(1); }
const IN = JSON.parse(fs.readFileSync('/tmp/tk_input.json', 'utf8'))[OID];
if (!IN) { console.log('无输入数据', OID); process.exit(1); }
const SHOP = 'Ljbgkj';
const IS_KID = /baby|kid|infant|toddler|children|newborn/i.test(IN.title);
const wait = ms => new Promise(z => setTimeout(z, ms));
const log = (...a) => console.log(' ', ...a);
const DIMS = (() => { const W = Math.max(100, Math.round(IN.weight * 1.3));
return { L: Math.max(60, Math.min(400, W)), Wi: Math.max(40, Math.min(300, Math.round(W * 0.6))), H: Math.max(10, Math.min(200, Math.round(W * 0.2))) }; })();
const tl = await (await fetch('http://127.0.0.1:9223/json/list')).json();
let k = 0;
for (const t of tl.filter(x => x.type === 'page' && /shopee/i.test(x.url))) { await fetch(`http://127.0.0.1:9223/json/close/${t.id}`).catch(() => {}); k++; }
if (k) { log(`清理 shopee 页 ${k} 个`); 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/shopeeGlobal/add' });
await wait(22000);
// 1. 店铺
async function pickShop() {
for (let a = 0; a < 3; a++) {
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?it.querySelector('.ant-select-selector'):[...document.querySelectorAll('.ant-select-selector')].filter(e=>e.offsetParent!==null)[0];
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 (!pos.length) return 'no-select';
for (const type of ['mousePressed', 'mouseReleased']) await c.send('Input.dispatchMouseEvent', { type, x: pos[0], y: pos[1], button: 'left', clickCount: 1 });
await wait(2200);
const r = 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=>new RegExp('^\\\\s*${SHOP}\\\\s*$','i').test(o.innerText||''));
if(!hit)return'no-hit'; for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'picked';})()`);
await wait(7000);
const cur = 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&&it.querySelector('.ant-select-selection-item'); return s?s.innerText.trim():'';})()`));
if (new RegExp(SHOP, 'i').test(cur)) return 'ok:' + cur;
log(' 店铺重试', a + 1, r, JSON.stringify(cur));
}
return 'fail';
}
// 2. 分类(同 TikTok 结构)
async function pickCategory(kw) {
await c.evalJS(`(()=>{document.querySelectorAll('.ant-select-dropdown').forEach(d=>{if(d.offsetParent!==null)d.style.display='none';}); document.body.click(); return 1;})()`);
await wait(900);
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||'');});
if(!it)return'[]'; const b=[...it.querySelectorAll('button,a,span')].filter(e=>e.offsetParent!==null&&/^\\s*选择分类\\s*$/.test((e.innerText||'').trim()));
if(!b.length)return'[]'; const el=b[b.length-1]; el.scrollIntoView({block:'center'}); const r=el.getBoundingClientRect();
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
if (!pos.length) return 'no-btn';
for (const type of ['mousePressed', 'mouseReleased']) await c.send('Input.dispatchMouseEvent', { type, x: pos[0], y: pos[1], button: 'left', clickCount: 1 });
await wait(3500);
const r = await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(!m)return'no-modal'; const inp=m.querySelector('input[placeholder="搜索分类名称"]'); if(!inp)return'no-input';
inp.focus(); Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set.call(inp,${JSON.stringify(kw)});
inp.dispatchEvent(new Event('input',{bubbles:true})); inp.dispatchEvent(new Event('change',{bubbles:true}));
const b=[...m.querySelectorAll('button')].find(x=>/^\\s*搜索\\s*$/.test(x.innerText||''));
if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
return 'searched';})()`);
if (r !== 'searched') return r;
await wait(4000);
const pick = await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(!m)return'no-modal'; const its=[...m.querySelectorAll('.search-result-item')]; if(!its.length)return'no-result';
const BAD=/二手|Barang Terpakai|Second-?hand|Used|Pre-?owned|Refurb|Sexual|Sex Toy|情趣|Adult Toy|Dewasa/i;
const KID=/Bayi|Baby|Kids|Kid|Infant|Toddler|Children|Kanak/i;
const ISK=${IS_KID};
const KW=${JSON.stringify(kw)}.toLowerCase();
const texts=its.map(e=>(e.innerText||'').replace(/\s+/g,' ').trim());
const lastSeg=t=>{const a=t.split('/'); return (a[a.length-1]||'').replace(/\(.*?\)/g,'').trim().toLowerCase();};
let idx=texts.findIndex(t=>!BAD.test(t) && lastSeg(t).includes(KW));
if(idx<0) idx=texts.findIndex(t=>!BAD.test(t) && t.toLowerCase().includes(KW) && (ISK || !KID.test(t)));
if(idx<0) idx=texts.findIndex(t=>!BAD.test(t) && (ISK || !KID.test(t)));
if(idx<0) idx=texts.findIndex(t=>!BAD.test(t));
if(idx<0) idx=0;
const hit=its[idx];
for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
return 'picked['+idx+'/'+texts.length+']:'+texts[idx];})()`);
await wait(4500);
return pick;
}
async function pickCategoryAny(kws) {
const tried = [];
for (const kw of kws) {
const r = String(await pickCategory(kw));
tried.push(kw + '\u2192' + r.slice(0, 46));
if (!/no-result|no-input|no-modal|no-btn/.test(r)) return { r, tried };
await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(m){const x=m.querySelector('.ant-modal-close'); if(x&&x.offsetParent!==null)x.click();} return 1;})()`);
await wait(1500);
}
return { r: 'ALL-FAILED', tried };
}
log('=== Shopee 建品 ===', OID, IN.title.slice(0, 46));
log('1) 店铺:', await pickShop());
const kw = CAT_KW || IN.sp_kw || 'Accessories';
const catRes = await pickCategoryAny([kw].concat(IN.sp_fb || []));
log('2) 分类:', SAN(String(catRes.r)).slice(0, 120), '| 尝试:', catRes.tried.join(' / '));
if (/ALL-FAILED|no-result|no-input|no-btn/.test(String(catRes.r))) { log('\u274c 分类未选中,跳过保存'); process.exit(2); }
// 3. 单件模式 + 文案
const wr = await c.evalJS(`(()=>{const p=document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
const ps=p._s.get('shopeeGlobalProductStore').$state.formState;
ps.type='single';
ps.title=${JSON.stringify(IN.title)};
const txt=${JSON.stringify(IN.bullets.map(b => '• ' + b).join('\n') + '\n\nKeywords: ' + (IN.keywords || ''))};
ps.descriptionInfo={descriptionText:txt, descriptionHtml:'<p>'+${JSON.stringify(IN.bullets.join('<br>'))}+'</p>'};
return 'ok:'+ps.title.length;})()`);
log('3) 文案:', wr);
await wait(2000);
// 4. 价格 / 库存 / 重量 / 尺寸
const setItem = (rx, sel, val) => c.evalJS(`(()=>{
const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(x=>{const l=x.querySelector('label'); return l&&new RegExp(${JSON.stringify(rx)}).test(l.innerText||'');});
const el=it?it.querySelector(${JSON.stringify(sel)}):null; if(!el)return'nf';
const proto=el.tagName==='TEXTAREA'?window.HTMLTextAreaElement.prototype:window.HTMLInputElement.prototype;
Object.getOwnPropertyDescriptor(proto,'value').set.call(el, ${JSON.stringify(String(val))});
el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true})); el.dispatchEvent(new Event('blur',{bubbles:true})); return 'ok';})()`);
log('4) 价格(CNY):', await setItem('价格', 'input:not([type=hidden])', IN.price_cny));
log(' 库存:', await setItem('库存', 'input:not([type=hidden])', '999'));
log(' 重量:', await setItem('重量', 'input:not([type=hidden])', IN.weight));
const dim = 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||'');});
if(!it)return'nf'; const ins=[...it.querySelectorAll('input')];
const setV=(el,v)=>{ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set.call(el,String(v));
el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true})); el.dispatchEvent(new Event('blur',{bubbles:true})); };
const L=ins.find(i=>i.placeholder==='长')||ins[0], W2=ins.find(i=>i.placeholder==='宽')||ins[1], H=ins.find(i=>i.placeholder==='高')||ins[2];
if(L)setV(L,${DIMS.L}); if(W2)setV(W2,${DIMS.Wi}); if(H)setV(H,${DIMS.H}); return 'ok:'+ins.length;})()`);
log('5) 尺寸:', dim, JSON.stringify(DIMS));
// 5. 图片
const ir = await c.evalJS(`(()=>{const p=document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
const st=p._s.get('shopeeGlobalImageInfoStore').$state;
const urls=${JSON.stringify(IN.imgs)};
st.imageInfo.mainImages=urls.map((u,i)=>({url:u,imgUrl:u,name:'img'+(i+1)+'.jpg',width:800,height:800,checked:true}));
return 'imgs:'+st.imageInfo.mainImages.length;})()`);
log('6) 图片:', ir, '(共', IN.imgs.length, ')');
await wait(2500);
log('7) 来源URL:', await setItem('来源URL', 'input:not([type=hidden])', 'https://detail.1688.com/offer/' + OID + '.html'));
await wait(1200);
const st = await c.evalJS(`(()=>{const p=document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
const b=p._s.get('shopeeGlobalBasicStore').$state;
return JSON.stringify({shopId:b.formState.shopId, cur:b.dataState.currency});})()`);
log('8) 保存前:', st);
const sv = await c.evalJS(`(()=>{const b=[...document.querySelectorAll('button,a,span')].filter(e=>e.offsetParent!==null&&/^\\s*保存\\s*$/.test(e.innerText||''));
if(!b.length)return'nf'; for(const ev of ['mousedown','mouseup','click']) b[b.length-1].dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`);
log('9) 保存:', sv);
await wait(9000);
const msg = await c.evalJS(`(()=>{const ms=[...document.querySelectorAll('.ant-message-notice,.ant-notification-notice,.ant-modal')].filter(e=>e.offsetParent!==null)
.map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,170)).filter(Boolean); return JSON.stringify({url:location.href, msgs:ms.slice(0,4)});})()`);
log('10) 结果:', SAN(String(msg)).slice(0, 400));
await c.shot('/tmp/sp_pilot.jpeg').catch(() => {});
process.exit(0);
+94
View File
@@ -0,0 +1,94 @@
import { newTarget, CDP, SAN } from '/tmp/cdp3.mjs';
/* 就地改 Shopee 产品类目:node spfixcat.mjs <productId> <title> <kw1,kw2,...> */
const PID = process.argv[2];
const TITLE = process.argv[3] || '';
const KWS = (process.argv[4] || '').split(',').filter(Boolean);
if (!PID || !KWS.length) { console.log('用法: node spfixcat.mjs <productId> <title> <kw1,kw2>'); process.exit(1); }
const wait = ms => new Promise(z => setTimeout(z, ms));
const log = (...a) => console.log(' ', ...a);
const IS_KID = /baby|kid|infant|toddler|children|newborn/i.test(TITLE);
const IS_AUTO = /car|auto|moto|vehicle|truck|bicycle|bike/i.test(TITLE);
const tl = await (await fetch('http://127.0.0.1:9223/json/list')).json();
for (const t of tl.filter(x => x.type === 'page' && /shopee/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/shopeeGlobal/edit?id=${PID}` });
await wait(26000);
for (let i = 0; i < 8; i++) {
const x = await c.evalJS(`(()=>{const ms=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null);
if(!ms.length)return'n'; ms.forEach(m=>{const cb=m.querySelector('.ant-modal-close'); if(cb&&cb.offsetParent!==null)cb.click();}); return 'c';})()`);
if (x === 'n') break; await wait(1000);
}
await wait(2000);
log('URL:', await c.evalJS('location.href'));
log('店铺:', 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&&it.querySelector('.ant-select-selection-item'); return s?s.innerText.trim():'';})()`));
async function pickCategory(kw) {
await c.evalJS(`(()=>{document.querySelectorAll('.ant-select-dropdown').forEach(d=>{if(d.offsetParent!==null)d.style.display='none';}); document.body.click(); return 1;})()`);
await wait(900);
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||'');});
if(!it)return'[]'; const b=[...it.querySelectorAll('button,a,span')].filter(e=>e.offsetParent!==null&&/^\\s*选择分类\\s*$/.test((e.innerText||'').trim()));
if(!b.length)return'[]'; const el=b[b.length-1]; el.scrollIntoView({block:'center'}); const r=el.getBoundingClientRect();
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
if (!pos.length) return 'no-btn';
for (const type of ['mousePressed', 'mouseReleased']) await c.send('Input.dispatchMouseEvent', { type, x: pos[0], y: pos[1], button: 'left', clickCount: 1 });
await wait(3500);
const r = await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(!m)return'no-modal'; const inp=m.querySelector('input[placeholder="搜索分类名称"]'); if(!inp)return'no-input';
inp.focus(); Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set.call(inp,${JSON.stringify(kw)});
inp.dispatchEvent(new Event('input',{bubbles:true})); inp.dispatchEvent(new Event('change',{bubbles:true}));
const b=[...m.querySelectorAll('button')].find(x=>/^\\s*搜索\\s*$/.test(x.innerText||''));
if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
return 'searched';})()`);
if (r !== 'searched') return r;
await wait(4000);
const pick = await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(!m)return'no-modal'; const its=[...m.querySelectorAll('.search-result-item')]; if(!its.length)return'no-result';
const BAD=/二手|Second-?hand|Used|Pre-?owned|Refurb|Sexual|Sex Toy|情趣|Adult Toy|Dewasa/i;
const KID=/Bayi|Baby|Kids|Kid|Infant|Toddler|Children|Kanak/i;
const AUTO=/Automobile|Automotive|Motosikal|汽车|车贴|Emblem/i;
const ISK=${IS_KID}, ISA=${IS_AUTO};
const KW=${JSON.stringify(kw)}.toLowerCase();
const texts=its.map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim());
const ok=t=>!BAD.test(t)&&(ISK||!KID.test(t))&&(ISA||!AUTO.test(t));
const lastSeg=t=>{const a=t.split('/'); return (a[a.length-1]||'').replace(/\\(.*?\\)/g,'').trim().toLowerCase();};
let idx=texts.findIndex(t=>ok(t)&&lastSeg(t).includes(KW));
if(idx<0) idx=texts.findIndex(t=>ok(t)&&t.toLowerCase().includes(KW));
if(idx<0) idx=texts.findIndex(t=>ok(t));
if(idx<0) idx=texts.findIndex(t=>!BAD.test(t));
if(idx<0) idx=0;
const hit=its[idx];
for(const ev of ['mousedown','mouseup','click']) hit.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
return 'picked['+idx+'/'+texts.length+']:'+texts[idx];})()`);
await wait(4500);
return pick;
}
let done = null;
for (const kw of KWS) {
const r = String(await pickCategory(kw));
log(' ', kw, '→', SAN(r).slice(0, 130));
if (!/no-result|no-input|no-modal|no-btn/.test(r)) { done = r; break; }
await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop();
if(m){const x=m.querySelector('.ant-modal-close'); if(x&&x.offsetParent!==null)x.click();} return 1;})()`);
await wait(1500);
}
if (!done) { log('❌ 全部关键词无结果'); process.exit(2); }
const sv = await c.evalJS(`(()=>{const b=[...document.querySelectorAll('button,a,span')].filter(e=>e.offsetParent!==null&&/^\\s*保存\\s*$/.test(e.innerText||''));
if(!b.length)return'nf'; for(const ev of ['mousedown','mouseup','click']) b[b.length-1].dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`);
log('保存:', sv);
await wait(9000);
const msg = await c.evalJS(`(()=>{const ms=[...document.querySelectorAll('.ant-message-notice,.ant-notification-notice')].filter(e=>e.offsetParent!==null)
.map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,140)).filter(Boolean); return JSON.stringify(ms.slice(0,3));})()`);
log('结果:', SAN(String(msg)).slice(0, 260));
process.exit(done ? 0 : 2);