1

hace poco comenze a aprender sobre puppeteer para hacer scrapping de paginas web, para practicar he decidido intentar con la pokedex en la pagina: https://www.pokemon.com/us/pokedex/. De esta quiero sacar nombre del pokemon y su numero de id (Anexo imagen) [![][1]][1]

Ese es el codigo resultante luego de intentarlo

const puppeteer = require ('puppeteer');
(async () => {
    const browser = await puppeteer.launch({ headless: false });
    const page = await browser.newPage();
    await page.goto('https://www.pokemon.com/us/pokedex/');
    await page.waitForSelector("h5");
    await page.waitFor(3000);
    const pokemon = await page.evaluate(() => {
    const pokes1 = document.querySelectorAll('h5');
    const id = document.querySelectorAll('p.id');
    const valor = {};
    for (let poke1 of pokes1) {
        valor.push(poke1.textContent);
    }
    return valor;
    })
    console.log (pokemon);
    await browser.close();
})();

Pasa que al ejecutarlo con cmd me sale esto y no se que hacer para solucionarlo [![][2]][2]

Espero y me pueden ayudar porque no se que hacer la verdad, abrazos!

Microsoft Windows [Version 10.0.18363.1139]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\susan>node index2.js
waitFor is deprecated and will be removed in a future release. See https://github.com/puppeteer/puppeteer/issues/6214 for details and how to migrate your code.
(node:9680) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: valor.push is not a function
    at __puppeteer_evaluation_script__:6:15
    at ExecutionContext._evaluateInternal (C:\Users\susan\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:217:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async ExecutionContext.evaluate (C:\Users\susan\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:106:16)
    at async C:\Users\susan\index2.js:8:21
(node:9680) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9680) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2
  • Por favor, podrías quitar la imagen y poner el error como texto?
    – braver
    el 19 oct. 2020 a las 17:05
  • Claro @braver lo acabo de editar, gracias!
    – Wilmer
    el 19 oct. 2020 a las 17:14

1 respuesta 1

0

Error: Evaluation failed: TypeError: valor.push is not a function

Este error significa que el atributo push de valor no es una función. Esto pasa porque al acceder a un atributo que no fue definido en un objeto de Javascript, la expresión se evalua en undefined.

Si quieres usar una lista en la que le puedas "meter" objetos con push debes usar Array. Por ejemplo:

const valor = []; // en vez de `{}`

for (let poke1 of pokes1) {
    valor.push(poke1.textContent);
}
1
  • Muchisimas gracias @braver, me salvaste
    – Wilmer
    el 19 oct. 2020 a las 18:43

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.