Actualizar robot_cobros.js
This commit is contained in:
parent
fddd71c5f8
commit
47bac60db6
|
|
@ -29,7 +29,7 @@ app.use(express.json());
|
|||
// --- ENDPOINT UNIFICADO ---
|
||||
app.post('/api/robot-cobros', async (req, res) => {
|
||||
const { action, urls } = req.body;
|
||||
console.log(`🔔 Orden recibida: ${action.toUpperCase()}`);
|
||||
console.log(`🔔 Orden recibida: ${action ? action.toUpperCase() : 'DESCONOCIDA'}`);
|
||||
|
||||
try {
|
||||
if (action === 'scan') {
|
||||
|
|
@ -42,7 +42,7 @@ app.post('/api/robot-cobros', async (req, res) => {
|
|||
res.json({ success: true, mode: 'process', count: procesados });
|
||||
}
|
||||
else {
|
||||
throw new Error("Acción no válida");
|
||||
throw new Error("Acción no válida o faltan parámetros.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("❌ Error:", err.message);
|
||||
|
|
@ -95,21 +95,21 @@ async function runProcessor(urlsAProcesar) {
|
|||
await page.waitForTimeout(1500);
|
||||
|
||||
// 2. BUSCAR BOTÓN ESPECÍFICO "DESGLOSE SERVICIOS"
|
||||
// Buscamos cualquier botón/input que contenga la palabra "SERVICIOS" (ignorando mayusc/minusc)
|
||||
console.log(" 🔘 Buscando botón 'Desglose Servicios'...");
|
||||
|
||||
const botonPulsado = await page.evaluate(() => {
|
||||
// Buscamos en inputs (tipo submit/button), botones y enlaces
|
||||
// Buscamos inputs, botones y enlaces
|
||||
const elementos = Array.from(document.querySelectorAll('input[type="button"], input[type="submit"], button, a'));
|
||||
|
||||
// Filtramos el que tenga "SERVICIOS" y "DESGLOSE" en su texto o valor
|
||||
// Opción A: Buscar texto exacto "DESGLOSE" y "SERVICIO"
|
||||
const target = elementos.find(el => {
|
||||
const texto = (el.value || el.innerText || "").toUpperCase();
|
||||
return texto.includes("SERVICIO") && texto.includes("DESGLOSE");
|
||||
});
|
||||
|
||||
// Si no encontramos uno tan específico, probamos solo con "SERVICIOS" dentro de la tabla de botones
|
||||
const targetSecundario = elements.find(el => (el.value || el.innerText || "").toUpperCase().includes("SERVICIOS"));
|
||||
// Opción B (Fallback): Buscar solo "SERVICIOS" si falla lo anterior
|
||||
// CORRECCIÓN AQUÍ: antes ponía 'elements' y fallaba
|
||||
const targetSecundario = elementos.find(el => (el.value || el.innerText || "").toUpperCase().includes("SERVICIOS"));
|
||||
|
||||
const finalTarget = target || targetSecundario;
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ async function runProcessor(urlsAProcesar) {
|
|||
|
||||
if (botonPulsado) {
|
||||
console.log(" ✅ Botón pulsado. Esperando tabla...");
|
||||
await page.waitForTimeout(3000); // Esperar a que cargue la tabla de datos
|
||||
await page.waitForTimeout(3000);
|
||||
} else {
|
||||
console.warn(" ⚠️ No encontré el botón de Servicios. Intentando leer por si ya estamos dentro.");
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ async function runProcessor(urlsAProcesar) {
|
|||
const servicio = tds[0].innerText.trim();
|
||||
const saldoRaw = tds[5].innerText.trim();
|
||||
|
||||
// Validar que sea un número de servicio real
|
||||
// Validar que sea un número de servicio real (5 o más dígitos)
|
||||
if (/^\d{5,}$/.test(servicio)) {
|
||||
datos.push({ servicio, saldoRaw });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue