Actualizar robot.js
This commit is contained in:
59
robot.js
59
robot.js
@@ -281,7 +281,7 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 🧹 HOMESERVE (MODO DEBUG ACTIVADO + SCRAPING MANTENIDO)
|
// 🧹 HOMESERVE (SOLO SE HAN AÑADIDO LOGS)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
||||||
const browser = await chromium.launch({
|
const browser = await chromium.launch({
|
||||||
@@ -295,58 +295,30 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
|||||||
});
|
});
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
try {
|
try {
|
||||||
console.log("🌍 [HomeServe] Iniciando navegación a la página de login...");
|
console.log("🌍 [HomeServe] Entrando a la página de login...");
|
||||||
await gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=PROF_PASS');
|
await gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=PROF_PASS');
|
||||||
|
|
||||||
// 1. COMPROBAR SI ESTAMOS EN EL LOGIN
|
console.log(`🔎 [HomeServe] URL tras cargar login: ${page.url()}`);
|
||||||
const tieneUser = await page.isVisible('input[name="CODIGO"]');
|
|
||||||
const tienePass = await page.isVisible('input[type="password"]');
|
|
||||||
|
|
||||||
if (tieneUser && tienePass) {
|
if (await page.isVisible('input[name="CODIGO"]')) {
|
||||||
console.log(`🔑 [HomeServe] Formulario detectado. Intentando login para usuario: ${user}...`);
|
console.log("✅ [HomeServe] Formularios de login encontrados. Rellenando...");
|
||||||
await page.fill('input[name="CODIGO"]', user);
|
await page.fill('input[name="CODIGO"]', user);
|
||||||
await page.fill('input[type="password"]', pass);
|
await page.fill('input[type="password"]', pass);
|
||||||
|
|
||||||
console.log("⌨️ [HomeServe] Pulsando Enter...");
|
|
||||||
await page.keyboard.press('Enter');
|
await page.keyboard.press('Enter');
|
||||||
|
console.log("⌨️ [HomeServe] Pulsado Enter. Esperando 5 segundos...");
|
||||||
// Esperamos a que la URL cambie o cargue algo
|
await page.waitForTimeout(5000);
|
||||||
await page.waitForTimeout(6000);
|
console.log(`👀 [HomeServe] URL después del login: ${page.url()}`);
|
||||||
|
|
||||||
// 2. VERIFICAR SI EL LOGIN FALLÓ
|
|
||||||
const errorMsg = await page.evaluate(() => {
|
|
||||||
// Buscamos textos comunes de error en HomeServe
|
|
||||||
const body = document.body.innerText.toUpperCase();
|
|
||||||
if (body.includes("ERROR") || body.includes("INCORRECTA") || body.includes("DENEGADO")) {
|
|
||||||
return body.substring(0, 100); // Nos devuelve el principio del error
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (errorMsg) {
|
|
||||||
console.error(`❌ [HomeServe] ¡ERROR DE AUTENTICACIÓN!: ${errorMsg}`);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`✅ [HomeServe] Parece que hemos entrado. URL actual: ${page.url()}`);
|
console.log("⚠️ [HomeServe] NO se encontró el campo CODIGO en la página.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
console.log("📋 [HomeServe] Yendo a lista_servicios_total...");
|
||||||
console.log("⚠️ [HomeServe] No se ve el formulario de login. ¿Ya estábamos dentro o ha cambiado la web?");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. INTENTAR IR A LA LISTA
|
|
||||||
console.log("📋 [HomeServe] Yendo a la lista de servicios...");
|
|
||||||
await gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=lista_servicios_total');
|
await gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=lista_servicios_total');
|
||||||
await page.waitForTimeout(4000);
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
// 4. DEBUG DE LA TABLA
|
console.log(`📍 [HomeServe] URL actual de la lista: ${page.url()}`);
|
||||||
const debugTabla = await page.evaluate(() => {
|
|
||||||
const tabla = document.querySelector('table[bgcolor="#FCF4D6"]');
|
|
||||||
if (!tabla) return "NO ENCONTRADA";
|
|
||||||
const filas = tabla.querySelectorAll('tr').length;
|
|
||||||
return `ENCONTRADA con ${filas} filas`;
|
|
||||||
});
|
|
||||||
console.log(`📊 [HomeServe] Estado de la tabla: ${debugTabla}`);
|
|
||||||
|
|
||||||
|
// 🛑 NUEVO: Ahora extraemos la referencia Y LOS ICONOS de la misma pasada
|
||||||
const listaConIconos = await page.evaluate(() => {
|
const listaConIconos = await page.evaluate(() => {
|
||||||
const results = [];
|
const results = [];
|
||||||
const rows = Array.from(document.querySelectorAll('table[bgcolor="#FCF4D6"] tr'));
|
const rows = Array.from(document.querySelectorAll('table[bgcolor="#FCF4D6"] tr'));
|
||||||
@@ -373,11 +345,10 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
|||||||
|
|
||||||
if (refs.length > 0) {
|
if (refs.length > 0) {
|
||||||
await syncAndArchive(ownerId, 'homeserve', refs);
|
await syncAndArchive(ownerId, 'homeserve', refs);
|
||||||
console.log(`✅ [HomeServe] ${refs.length} expedientes detectados con éxito.`);
|
|
||||||
} else {
|
|
||||||
console.log("❓ [HomeServe] Login aparentemente OK pero 0 expedientes en la tabla.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`🔍 [HomeServe] ${refs.length} expedientes detectados.`);
|
||||||
|
|
||||||
for (const ref of refs) {
|
for (const ref of refs) {
|
||||||
await gotoWithRetry(page, `https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=ver_servicioencurso&Servicio=${ref}`);
|
await gotoWithRetry(page, `https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=ver_servicioencurso&Servicio=${ref}`);
|
||||||
await page.waitForTimeout(2000);
|
await page.waitForTimeout(2000);
|
||||||
|
|||||||
Reference in New Issue
Block a user