Actualizar robot.js
This commit is contained in:
67
robot.js
67
robot.js
@@ -113,42 +113,6 @@ 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-dev-shm-usage', '--disable-gpu']
|
||||
});
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
try {
|
||||
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);
|
||||
|
||||
console.log("📥 [Multi] Entrando al buzón...");
|
||||
await gotoWithRetry(page, 'https://web.multiasistencia.com/w3multi/frepasos_new.php?refresh=1');
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// 🔄 DOBLE RECARGA FORZADA PARA DESPERTAR AL SERVIDOR
|
||||
console.log("🔄 [Multi] Forzando doble recarga del buzón...");
|
||||
for (let i = 1; i <= 2; i++) {
|
||||
try {
|
||||
console.log(` 👉 Forzando recarga ${i}/2...`);
|
||||
await page.evaluate(() => {
|
||||
if (typeof refrescar === 'function') refrescar();
|
||||
else if (document.getElementById('recargar')) document.getElementById('recargar').click();
|
||||
});
|
||||
await page.waitForTimeout(3500);
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ Fallo menor en recarga ${i}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// --- BUCLE DE PAGINACIÓN INFALIBLE ---
|
||||
let todosExpedientes = new Set();
|
||||
let paginaActual = 1;
|
||||
@@ -156,7 +120,10 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
||||
console.log(`📄 [Multi] Iniciando lectura por páginas...`);
|
||||
while (true) {
|
||||
console.log(`\n📄 [Multi] Escaneando página ${paginaActual}...`);
|
||||
await page.waitForTimeout(1500);
|
||||
|
||||
// 🛑 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(() => {
|
||||
@@ -166,25 +133,31 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
||||
|
||||
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í.");
|
||||
break;
|
||||
}
|
||||
|
||||
unicosPagina.forEach(ref => todosExpedientes.add(ref));
|
||||
|
||||
// 2. BUSCAMOS Y PULSAMOS EL BOTÓN "SIGUIENTE" DIRECTAMENTE EN EL NAVEGADOR
|
||||
const hasNextPage = await page.evaluate(() => {
|
||||
// 2. BUSCAMOS Y PULSAMOS EL BOTÓN "SIGUIENTE"
|
||||
const clicked = await page.evaluate(() => {
|
||||
const links = Array.from(document.querySelectorAll('a.lnkheader'));
|
||||
// Buscamos ignorando si tiene flechitas (>>) o mayúsculas
|
||||
const nextBtn = links.find(a => a.innerText.toLowerCase().includes('siguiente'));
|
||||
if (nextBtn) {
|
||||
nextBtn.click(); // Ejecuta el javascript de la web internamente
|
||||
const btn = links.find(a => a.innerText.toLowerCase().includes('siguiente'));
|
||||
if (btn) {
|
||||
btn.click();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasNextPage) {
|
||||
console.log(` ➡️ Botón 'Siguiente' detectado. Pulsando y esperando a cargar...`);
|
||||
// Le damos 4 segundos a la web para que cargue la nueva página tras el click
|
||||
await page.waitForTimeout(4000);
|
||||
if (clicked) {
|
||||
console.log(` ➡️ Botón 'Siguiente' detectado. Pulsando y esperando a que cargue...`);
|
||||
// 🛑 EL FRENO: Congelamos el robot 5 segundos fijos para que el servidor responda
|
||||
await page.waitForTimeout(5000);
|
||||
paginaActual++;
|
||||
|
||||
if(paginaActual > 20) {
|
||||
console.log("⚠️ [Multi] Límite de 20 páginas alcanzado por seguridad.");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user