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