Actualizar robot.js
This commit is contained in:
19
robot.js
19
robot.js
@@ -168,17 +168,22 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
|
|||||||
console.log(` 👉 Encontrados ${unicosPagina.length} expedientes únicos en la pág. ${paginaActual}.`);
|
console.log(` 👉 Encontrados ${unicosPagina.length} expedientes únicos en la pág. ${paginaActual}.`);
|
||||||
unicosPagina.forEach(ref => todosExpedientes.add(ref));
|
unicosPagina.forEach(ref => todosExpedientes.add(ref));
|
||||||
|
|
||||||
// 2. BUSCAMOS LA URL DEL BOTÓN "SIGUIENTE"
|
// 2. BUSCAMOS Y PULSAMOS EL BOTÓN "SIGUIENTE" DIRECTAMENTE EN EL NAVEGADOR
|
||||||
const nextPageUrl = await page.evaluate(() => {
|
const hasNextPage = await page.evaluate(() => {
|
||||||
const links = Array.from(document.querySelectorAll('a.lnkheader'));
|
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'));
|
const nextBtn = links.find(a => a.innerText.toLowerCase().includes('siguiente'));
|
||||||
return nextBtn ? nextBtn.href : null;
|
if (nextBtn) {
|
||||||
|
nextBtn.click(); // Ejecuta el javascript de la web internamente
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nextPageUrl) {
|
if (hasNextPage) {
|
||||||
console.log(` ➡️ Botón 'Siguiente' detectado. Navegando a la url...`);
|
console.log(` ➡️ Botón 'Siguiente' detectado. Pulsando y esperando a cargar...`);
|
||||||
await gotoWithRetry(page, nextPageUrl);
|
// Le damos 4 segundos a la web para que cargue la nueva página tras el click
|
||||||
await page.waitForTimeout(3000);
|
await page.waitForTimeout(4000);
|
||||||
paginaActual++;
|
paginaActual++;
|
||||||
if(paginaActual > 20) {
|
if(paginaActual > 20) {
|
||||||
console.log("⚠️ [Multi] Límite de 20 páginas alcanzado por seguridad.");
|
console.log("⚠️ [Multi] Límite de 20 páginas alcanzado por seguridad.");
|
||||||
|
|||||||
Reference in New Issue
Block a user