Files
dianxiaomi-crossborder-play…/妙手建品/ms_login4.mjs
T

39 lines
3.3 KiB
JavaScript

import { listPages, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
import { CDP, SAN as S } from '/tmp/cdp3.mjs';
import { readFileSync } from 'fs';
const doc=readFileSync('/home/admin9webs/agent-a2-import/skills/ecommerce/miaoshou-erp/SKILL.md','utf8');
const acc=(doc.match(/xiaochaoren\d+/)||[])[0], pwd=(doc.match(/Bingo\d+@/)||[])[0];
const CAP=process.argv[2];
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 wait(1000);
const f=await c.evalJS(`(()=>{const set=(sel,v)=>{const el=document.querySelector(sel); if(!el) return 0;
const s=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set; s.call(el,v);
el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true})); return 1;};
return JSON.stringify({a:set('input.login-form__input[placeholder="手机号/子账号/邮箱"]', ${JSON.stringify(acc)}),
p:set('input.login-form__input[type=password]', ${JSON.stringify(pwd)}),
k:set('.captcha-field__input', ${JSON.stringify(CAP)}),
btn:!!document.querySelector('.login-form__submit-btn')});})()`);
console.log('填表:', S(String(f)).slice(0,150));
await wait(700);
await c.evalJS(`(()=>{const b=document.querySelector('.login-form__submit-btn'); if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 1;})()`);
await wait(12000);
console.log('登录:', S(String(await c.evalJS(`JSON.stringify({href:location.href, login:!!document.querySelector('input[type=password]'), err:[...document.querySelectorAll('*')].filter(e=>e.children.length===0&&/不正确|错误|锁定/.test(e.innerText||'')).map(e=>e.innerText.trim()).slice(0,2)})`))).slice(0,220));
await c.send('Page.navigate',{url:'https://erp.91miaoshou.com/common_collect_box/items'}); await wait(13000);
const pos=JSON.parse(String(await c.evalJS(`(()=>{const b=[...document.querySelectorAll('button')].filter(e=>e.offsetParent!==null&&(e.innerText||'').trim()==='导入产品');
if(!b.length) return '[]'; b[0].scrollIntoView({block:'center'}); const r=b[0].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(300);
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(7000);
}
const o=await c.evalJS(`(()=>{const dlgs=[...document.querySelectorAll('.jx-dialog,.jx-drawer,[class*=dialog]')].filter(e=>e.offsetParent!==null)
.map(e=>({txt:(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,280), btns:[...e.querySelectorAll('button')].map(b=>(b.innerText||'').trim()).filter(Boolean).slice(0,6)}));
const body=(document.body.innerText||'').replace(/\\s+/g,' ');
return JSON.stringify({dlgs:dlgs.slice(0,2), empty:/暂无数据/.test(body)});})()`);
console.log('导入产品:', S(String(o)).slice(0,1000));
try{ await c.shot('/tmp/ms_ip2.jpg'); console.log('shot ok'); }catch(e){}
process.exit(0);