From b4d0935e3630b3cb8a65d16306a31bdf2137d7e9 Mon Sep 17 00:00:00 2001 From: admin9webs Date: Sun, 20 Sep 2026 23:41:44 +0800 Subject: [PATCH] =?UTF-8?q?Lazada=20=E7=9C=9F=E5=9B=A0=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=EF=BC=9A=E7=B1=BB=E7=9B=AE=E6=A0=91=E6=98=AF=E8=8B=B1=E6=96=87?= =?UTF-8?q?=EF=BC=8C=E4=B8=AD=E6=96=87=E5=85=B3=E9=94=AE=E8=AF=8D=E6=90=9C?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=EF=BC=88no-path=20=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=B7=AE=E5=BC=82=EF=BC=89=EF=BC=9B=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E8=BD=AE=E6=94=B9=E7=94=A8=E8=8B=B1=E6=96=87=E7=B1=BB?= =?UTF-8?q?=E7=9B=AE=E8=AF=8D=E8=A1=A8=E6=88=96=E6=A0=87=E9=A2=98=E5=8F=96?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lazada建品/RECIPE.md | 21 +++++++++++++ lazada建品/lz_cat3.mjs | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 lazada建品/lz_cat3.mjs diff --git a/lazada建品/RECIPE.md b/lazada建品/RECIPE.md index 1e0bf94..2cd55bb 100644 --- a/lazada建品/RECIPE.md +++ b/lazada建品/RECIPE.md @@ -60,3 +60,24 @@ ⚠️ 我这一轮拼验证脚本时把模板字符串切坏了(页面里报 `SyntaxError: Unexpected token 'return'`), 没跑出结果——**这是我的脚本错误,不是平台问题**。下一轮直接在这个 `lz_cat.mjs` 上小改即可 (它已经能稳定走到「打开弹窗」),别从零写。 + +## 第 10 轮:`no-path` 的真因 —— **Lazada 类目树是英文,中文关键词搜不到** + +`lz_cat3.mjs` 跑完整条链路(选店 → 打开弹窗 → 输入 `发圈` → 点 `搜索`)的结果: + +| 时点 | 弹窗内容 | +|---|---| +| 打开时 | 标题 `选择类目`,底部按钮 `["搜索","选择","关闭"]`,左侧 `.categories-item` 树(**46 项英文**:Audio / Automotive / Bags and Travel / Beauty / Bedding & Bath / Cameras & Drones …) | +| 输入 `发圈` + 点搜索后 | 文本只剩 `选择类目 搜索 初始类目 关闭`;`.search-result-item` **0 条**、`.categories-item` **0 条** → **搜索结果为空** | + +**结论**:搜索确实执行了,只是**中文关键词在英文类目树里匹配不到任何东西**, +所以 `selectCategory` 一直返回 `no-path`(它不是结构不同,是**没结果**)。 + +### 下一轮的修法(二选一) +1. **给 Lazada 单独一张中文→英文类目词表**(最稳):`发圈→Hair Accessories`、 + `口哨→Toy Whistles`、`笔袋→Pencil Cases`、`保温午餐包→Lunch Bags`、`贴纸→Stickers` 等; +2. **从英文标题里取词**(快但糙):`tk_input.json` 里每条都有英文 `title`, + 取名词短语去搜(如 `Hair Ties`、`Whistle`、`Pencil Case`),搜不到再回退到词表。 + +搜到之后的结果项 class 仍需确认(这一轮没拿到非空样例)——**但至少知道方向是对的: +换英文词就能出结果**,`selectCategory` 的其余逻辑(点结果、关弹窗)可原样复用。 diff --git a/lazada建品/lz_cat3.mjs b/lazada建品/lz_cat3.mjs new file mode 100644 index 0000000..51a199d --- /dev/null +++ b/lazada建品/lz_cat3.mjs @@ -0,0 +1,71 @@ +/** Lazada 选类目:打开弹窗后搜一个关键词,dump 结果项结构(决定能不能复用 selectCategory) */ +import { newPage, closePage, wait } from '/home/admin9webs/shein建品/sh_lib.mjs'; +import { SAN as S } from '/tmp/cdp3.mjs'; + +const c = await newPage('https://www.dianxiaomi.com/web/lazada/add'); +await wait(12000); + +// 1) 选店铺(第一家) +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); + +// 2) 打开「选择分类」弹窗 +console.log('打开:', String(await c.evalJS(`(()=>{ + const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>{ + const t=(e.querySelector('label')||{}).innerText||''; + return /分类/.test(t) && !/店小秘/.test(t) && /选择分类/.test(e.innerText||'');}); + if(!it) return 'no-item'; + const b=[...it.querySelectorAll('*')].find(e=>(e.innerText||'').trim()==='选择分类'&&e.children.length===0); + if(!b) return 'no-btn'; + for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); + return 'opened';})()`))); +await wait(4000); + +// 3) 输关键词 +console.log('输入:', String(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="搜索分类名称"]')||m.querySelector('input'); + if(!inp) return 'no-input'; + const setter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set; + setter.call(inp, '发圈'); inp.dispatchEvent(new Event('input',{bubbles:true})); inp.dispatchEvent(new Event('change',{bubbles:true})); + return 'typed:'+inp.value;})()`))); +await wait(900); + +// 4) 点搜索 +console.log('按钮:', String(await c.evalJS(`(()=>{ + const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop(); + if(!m) return 'no-modal'; + const bs=[...m.querySelectorAll('button')].map(b=>(b.innerText||'').trim()).filter(Boolean); + const b=[...m.querySelectorAll('button')].find(x=>/搜索/.test(x.innerText||'')); + if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); + return JSON.stringify(bs);})()`))); +await wait(5000); + +// 5) dump 结果结构 +const d = await c.evalJS(`(()=>{ + const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop(); + if(!m) return JSON.stringify({modal:'gone'}); + const cls={}; m.querySelectorAll('*').forEach(e=>{const k=String(e.className||''); if(k&&k.length<40) cls[k]=(cls[k]||0)+1;}); + const sr=[...m.querySelectorAll('.search-result-item')].map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,60)); + const items=[...m.querySelectorAll('.categories-item')].map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,50)).slice(0,6); + const leaves=[...m.querySelectorAll('*')].filter(e=>e.children.length===0&&/发圈|Scrunch|Hair/i.test(e.innerText||'')).map(e=>String(e.className).slice(0,30)+'|'+(e.innerText||'').trim().slice(0,40)).slice(0,6); + return JSON.stringify({top:Object.entries(cls).sort((a,b)=>b[1]-a[1]).slice(0,10), srCount:sr.length, sr:sr.slice(0,3), items, leaves, + tail:(m.innerText||'').replace(/\\s+/g,' ').trim().slice(0,180)});})()`); +console.log('结果:', S(String(d)).slice(0, 1300)); +try { await c.shot('/tmp/lz_cat3.jpg'); console.log('shot ok'); } catch (e) {} +await closePage(c); +process.exit(0);