v10.12 修复hr1打招呼失败: 开弹窗改Playwright原生点击(合成click被平台反自动化检测拦截返回空壳弹窗); 新增空壳弹窗识别+重试+跳过逻辑
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// 深度诊断:按机器人的完整流程开弹窗→点打招呼,抓每一步的真实状态
|
||||
const pw = require('playwright-core');
|
||||
(async () => {
|
||||
const b = await pw.chromium.connectOverCDP('http://127.0.0.1:9223');
|
||||
const p = b.contexts()[0].pages().find(x => /recommend/.test(x.url()));
|
||||
|
||||
// 1. 找一个没打过招呼的卡片(按钮是"打招呼"而不是"继续沟通")
|
||||
const idx = await p.evaluate(() => {
|
||||
const cards = [...document.querySelectorAll('.recommend-item')];
|
||||
for (let i = 0; i < cards.length; i++) {
|
||||
const t = cards[i].querySelector('.cv-test-recommend-chat')?.innerText?.trim();
|
||||
if (t === '打招呼') return i;
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
console.log('待打招呼卡片索引:', idx);
|
||||
if (idx < 0) { console.log('当前可见卡片都已打过招呼'); process.exit(0); }
|
||||
|
||||
// 2. 开弹窗
|
||||
await p.evaluate((i) => {
|
||||
document.querySelectorAll('.recommend-item')[i].querySelector('.resume-item__content')?.click();
|
||||
}, idx);
|
||||
await new Promise(r => setTimeout(r, 3500));
|
||||
|
||||
// 3. 抓弹窗完整状态
|
||||
const st = await p.evaluate(() => {
|
||||
const m = document.querySelector('.new-shortcut-resume__modal');
|
||||
if (!m) return { modalOpen: false };
|
||||
const btn = m.querySelector('button.km-button--primary.km-button--filled');
|
||||
return {
|
||||
modalOpen: true,
|
||||
name: m.innerText.split('\n')[0]?.slice(0, 15),
|
||||
btnText: btn?.innerText?.trim() || '(无)',
|
||||
btnDisabled: btn?.disabled ?? null,
|
||||
// 弹窗里有没有任何提示性文案
|
||||
hints: (m.innerText.match(/(上线|上限|权益|开通|会员|到期|联系顾问)[^\n]{0,20}/g) || []).slice(0, 3),
|
||||
};
|
||||
});
|
||||
console.log('弹窗状态:', JSON.stringify(st, null, 1));
|
||||
|
||||
// 4. 点按钮 + 监听点击后的网络请求结果(打招呼API的响应)
|
||||
if (st.modalOpen && st.btnText === '打招呼') {
|
||||
const respPromise = p.waitForResponse(r => /greet|chat|hello|im\//i.test(r.url()), { timeout: 12000 }).catch(() => null);
|
||||
await p.evaluate(() => {
|
||||
const btn = document.querySelector('.new-shortcut-resume__modal button.km-button--primary.km-button--filled');
|
||||
btn?.click();
|
||||
});
|
||||
const resp = await respPromise;
|
||||
if (resp) {
|
||||
let body = '';
|
||||
try { body = (await resp.text()).slice(0, 200); } catch { }
|
||||
console.log('API响应:', resp.status(), resp.url().slice(0, 70), body);
|
||||
} else {
|
||||
console.log('点击后12秒内无相关网络请求(请求都没发出)');
|
||||
}
|
||||
// 最终按钮态
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
const fin = await p.evaluate(() => document.querySelector('.new-shortcut-resume__modal button.km-button--primary.km-button--filled')?.innerText?.trim());
|
||||
console.log('最终按钮态:', JSON.stringify(fin));
|
||||
await p.evaluate(() => document.querySelector('.new-shortcut-resume__close')?.click()).catch(() => { });
|
||||
}
|
||||
process.exit(0);
|
||||
})().catch(e => { console.log('ERR:', String(e).slice(0, 120)); process.exit(1); });
|
||||
Reference in New Issue
Block a user