Lazada 真因确认:类目树是英文,中文关键词搜不到(no-path 不是结构差异);下一轮改用英文类目词表或标题取词
This commit is contained in:
1 parent
5b5715d95a
commit
b4d0935e36
2 files changed
+92
No files matched your search
@@ -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` 的其余逻辑(点结果、关弹窗)可原样复用。
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user