Actualizar robot.js
This commit is contained in:
61
robot.js
61
robot.js
@@ -114,44 +114,55 @@ async function main() {
|
||||
// 🏥 MULTIASISTENCIA (PAGINACIÓN ANTIBALAS Y DOBLE RECARGA)
|
||||
// ==========================================
|
||||
async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
||||
const browser = await chromium.launch({ headless: HEADLESS, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'] });
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
try {
|
||||
const browser = await chromium.launch({ headless: HEADLESS, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu'] });
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
console.log("🌍 [Multi] Iniciando sesión...");
|
||||
await gotoWithRetry(page, 'https://web.multiasistencia.com/w3multi/acceso.php');
|
||||
await page.fill('input[name="usuario"]', user);
|
||||
await page.fill('input[type="password"]', pass);
|
||||
await page.click('input[type="submit"]');
|
||||
await page.waitForTimeout(4000);
|
||||
await gotoWithRetry(page, 'https://web.multiasistencia.com/w3multi/frepasos_new.php?refresh=1');
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
console.log("🔄 [Multi] Doble recarga manual...");
|
||||
await page.evaluate(() => { if (typeof refrescar === 'function') refrescar(); });
|
||||
await page.waitForTimeout(3000); // Espera de 3 segundos
|
||||
await page.evaluate(() => { if (typeof refrescar === 'function') refrescar(); });
|
||||
await page.waitForTimeout(5000); // Espera de 5 segundos
|
||||
|
||||
// --- BUCLE DE PAGINACIÓN INFALIBLE ---
|
||||
let todosExpedientes = new Set();
|
||||
let paginaActual = 1;
|
||||
|
||||
console.log(`📄 [Multi] Iniciando lectura por páginas...`);
|
||||
while (true) {
|
||||
console.log(`\n📄 [Multi] Escaneando página ${paginaActual}...`);
|
||||
console.log(`📄 [Multi] Escaneando página ${paginaActual}...`);
|
||||
await page.waitForSelector('a[href*="reparacion="]', { timeout: 8000 }).catch(() => {});
|
||||
|
||||
// 🛑 NUEVO: Esperamos a que los enlaces existan o damos 5 seg. de margen extra
|
||||
await page.waitForSelector('a[href*="reparacion="]', { timeout: 6000 }).catch(() => {});
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// 1. Extraemos los enlaces de esta página
|
||||
const expedientesPagina = await page.evaluate(() => {
|
||||
const refs = await page.evaluate(() => {
|
||||
const links = Array.from(document.querySelectorAll('a[href*="reparacion="]'));
|
||||
return links.map(a => a.href.match(/reparacion=(\d+)/)?.[1]).filter(Boolean);
|
||||
});
|
||||
|
||||
const unicosPagina = [...new Set(expedientesPagina)];
|
||||
console.log(` 👉 Encontrados ${unicosPagina.length} expedientes únicos en la pág. ${paginaActual}.`);
|
||||
|
||||
if (unicosPagina.length === 0) {
|
||||
console.log(" ⚠️ Página en blanco o cargando demasiado lento. Terminamos aquí.");
|
||||
const unicos = [...new Set(refs)];
|
||||
console.log(` 👉 Encontrados ${unicos.length} únicos.`);
|
||||
unicos.forEach(r => todosExpedientes.add(r));
|
||||
|
||||
const hasNext = await page.evaluate(() => {
|
||||
const btn = Array.from(document.querySelectorAll('a.lnkheader')).find(a => a.innerText.includes('siguiente') || a.innerText.includes('>>'));
|
||||
if (btn) { btn.click(); return true; }
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasNext && unicos.length === 15) {
|
||||
console.log(" ➡️ Pulsado 'Siguiente'. Esperando 6 segundos a que cargue...");
|
||||
await page.waitForTimeout(6000); // Freno de 6 segundos
|
||||
paginaActual++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unicosPagina.forEach(ref => todosExpedientes.add(ref));
|
||||
|
||||
@@ -244,26 +255,26 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
||||
"Teléfono": telefonoReal,
|
||||
"Estado": findByCab("Estado") || "",
|
||||
"Urgente": findByCab("Urgente") || "No"
|
||||
};
|
||||
};
|
||||
});
|
||||
if (scrapData && scrapData['Nombre Cliente']) break;
|
||||
} catch (e) { continue; }
|
||||
if (scrapData && scrapData['Nombre Cliente']) break;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
if (scrapData && scrapData['Nombre Cliente']) {
|
||||
// ESTO ES LO QUE TÚ ME HAS PASADO:
|
||||
if (scrapData && scrapData['Nombre Cliente']) {
|
||||
const idGremioDetectado = clasificarGremio(scrapData['Descripción'], gremiosDB);
|
||||
if (idGremioDetectado) {
|
||||
scrapData['guild_id'] = idGremioDetectado;
|
||||
}
|
||||
await saveServiceToDB(ownerId, 'multiasistencia', ref, scrapData);
|
||||
}
|
||||
} // Cierra el for (const ref of expedientesUnicos)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("❌ Error Multi:", e.message);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
} // Cierra async function runMultiasistencia
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 🧹 HOMESERVE (MEJORADO CON DECODIFICADOR, ICONOS Y URGENCIA)
|
||||
|
||||
Reference in New Issue
Block a user