Files

28 lines
2.0 KiB
JavaScript

import { listPages, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
import { CDP, SAN as S } from '/tmp/cdp3.mjs';
const t = (await listPages()).find(x=>/91miaoshou/i.test(x.url));
const c = await CDP.connect(t.webSocketDebuggerUrl);
await c.send('Page.enable'); await c.send('Runtime.enable');
await c.send('Page.navigate',{url:'https://erp.91miaoshou.com/common_collect_box/index?fetchType=importCopy'});
await wait(12000);
const pos = JSON.parse(String(await c.evalJS(`(()=>{
const rows=[...document.querySelectorAll('tr')].filter(e=>e.offsetParent!==null&&/^\\s*ms2\\s/.test((e.innerText||'').trim()));
const row=rows[0]; if(!row) return '[]';
const m=[...row.querySelectorAll('*')].find(e=>(e.innerText||'').trim()==='更多'&&e.children.length===0);
if(!m) return '[]'; m.scrollIntoView({block:'center'}); const r=m.getBoundingClientRect();
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
console.log('更多坐标:', JSON.stringify(pos));
if(pos.length){
await c.send('Input.dispatchMouseEvent',{type:'mouseMoved',x:pos[0],y:pos[1],buttons:0}); await wait(400);
for(const tp of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type:tp,x:pos[0],y:pos[1],button:'left',clickCount:1,buttons:1});
}
await wait(3000);
const o = await c.evalJS(`(()=>{
const items=[...document.querySelectorAll('.jx-dropdown-menu li,.jx-dropdown-menu__item,[class*=dropdown] li,[class*=menu] li')]
.filter(e=>e.offsetParent!==null).map(e=>(e.innerText||'').trim()).filter(Boolean);
const any=[...document.querySelectorAll('*')].filter(e=>e.offsetParent!==null&&e.children.length===0&&/采集|认领|发布|下载|重试|删除|查看/.test(e.innerText||'')&&(e.innerText||'').length<12).map(e=>(e.innerText||'').trim());
return JSON.stringify({menuItems:[...new Set(items)].slice(0,12), others:[...new Set(any)].slice(0,14)});})()`);
console.log('更多菜单:', S(String(o)).slice(0,600));
try{ await c.shot('/tmp/ms_more.jpg'); console.log('shot ok'); }catch(e){}
process.exit(0);