29 lines
2.3 KiB
JavaScript
29 lines
2.3 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');
|
|
try { await c.send('Browser.setDownloadBehavior',{behavior:'allow', downloadPath:'/home/admin9webs/miaoshou/dl', eventsEnabled:true}); console.log('下载目录已设置'); }
|
|
catch(e){ try { await c.send('Page.setDownloadBehavior',{behavior:'allow', downloadPath:'/home/admin9webs/miaoshou/dl'}); console.log('用 Page.setDownloadBehavior'); } catch(e2){ console.log('设置下载失败:', String(e2).slice(0,80)); } }
|
|
await wait(800);
|
|
// 确保在导入采集页
|
|
const href = String(await c.evalJS('location.href'));
|
|
if (!href.includes('importCopy')) {
|
|
console.log('切到导入采集页…');
|
|
await c.evalJS(`(()=>{const h=[...document.querySelectorAll('*')].filter(e=>e.offsetParent!==null&&(e.innerText||'').trim()==='导入采集'&&e.children.length===0);
|
|
if(h.length) for(const ev of ['mousedown','mouseup','click']) h[0].dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 1;})()`);
|
|
await wait(6000);
|
|
}
|
|
// 关掉可能的弹窗
|
|
await c.evalJS(`(()=>{const b=[...document.querySelectorAll('.jx-dialog__headerbtn,.jx-dialog__close')]; b.forEach(x=>x.click()); return 1;})()`);
|
|
await wait(1000);
|
|
// 点 导入链接采集
|
|
console.log('子模式:', String(await c.evalJS(`(()=>{const h=[...document.querySelectorAll('*')].filter(e=>e.offsetParent!==null&&(e.innerText||'').trim()==='导入链接采集'&&e.children.length===0);
|
|
if(!h.length) return 'nf'; for(const ev of ['mousedown','mouseup','click']) h[0].dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`)));
|
|
await wait(3000);
|
|
// 点 下载导入模板
|
|
console.log('下载模板:', String(await c.evalJS(`(()=>{const h=[...document.querySelectorAll('*')].filter(e=>e.offsetParent!==null&&/下载导入模板/.test(e.innerText||'')&&e.children.length===0&&(e.innerText||'').trim().length<12);
|
|
if(!h.length) return 'nf'; for(const ev of ['mousedown','mouseup','click']) h[0].dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`)));
|
|
await wait(8000);
|
|
process.exit(0);
|