妙手导入采集跑通:模板列名=xlrd读出,必须用 CSV(txt 要求 JSON、JSON 缺标题),47 条链接已入列等待解析
This commit is contained in:
1 parent
3de6adb832
commit
bbd5eb4bcf
7 files changed
+182
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { listPages, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
|
||||
import { CDP, SAN as S } from '/tmp/cdp3.mjs';
|
||||
const FILE = process.argv[2] || '/home/admin9webs/miaoshou/dl/links.txt';
|
||||
const t = (await listPages()).find(x=>/91miaoshou/i.test(x.url));
|
||||
const c = await CDP.connect(t.webSocketDebuggerUrl);
|
||||
await c.send('DOM.enable'); await c.send('Runtime.enable'); await wait(1000);
|
||||
// 先确保「导入链接采集」面板是打开的(上一次上传后面板会关掉)
|
||||
await c.evalJS(`(()=>{const close=[...document.querySelectorAll('.jx-dialog__headerbtn,.jx-dialog__close')]; close.forEach(x=>x.click()); return 1;})()`);
|
||||
await wait(800);
|
||||
const hasInput = async () => Number(await c.evalJS(`document.querySelectorAll('input.jx-upload__input').length`));
|
||||
if (!await hasInput()) {
|
||||
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(5000);
|
||||
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(3000);
|
||||
}
|
||||
console.log('上传控件数:', await hasInput());
|
||||
const { root } = await c.send('DOM.getDocument', { depth: -1 });
|
||||
const { nodeId } = await c.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'input.jx-upload__input' });
|
||||
console.log('文件输入 nodeId:', nodeId);
|
||||
if (!nodeId) { console.log('没找到上传控件'); process.exit(1); }
|
||||
await c.send('DOM.setFileInputFiles', { files: [FILE], nodeId });
|
||||
console.log('已注入文件:', FILE);
|
||||
await wait(4000);
|
||||
// 点确认
|
||||
console.log('确认:', String(await c.evalJS(`(()=>{const b=[...document.querySelectorAll('button')].filter(e=>e.offsetParent!==null).find(e=>/^\\s*确认\\s*$/.test((e.innerText||'').trim()));
|
||||
if(!b) return 'nf'; for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`)));
|
||||
await wait(9000);
|
||||
const o = await c.evalJS(`(()=>{
|
||||
const rows=[...document.querySelectorAll('tr')].filter(e=>e.offsetParent!==null).map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim()).filter(t=>t&&!/文件名称/.test(t)).slice(0,4);
|
||||
const toasts=[...document.querySelectorAll('[class*=message],[class*=toast],[class*=notice]')].filter(e=>e.offsetParent!==null).map(e=>(e.innerText||'').replace(/\\s+/g,' ').trim().slice(0,80)).filter(Boolean).slice(0,4);
|
||||
return JSON.stringify({rows, toasts});})()`);
|
||||
console.log('导入结果:', S(String(o)).slice(0,900));
|
||||
try{ await c.shot('/tmp/ms_upload.jpg'); console.log('shot ok'); }catch(e){}
|
||||
process.exit(0);
|
||||
Reference in new issue
Block a user