Estoy tratando de raspar los datos de esta página . La página tiene desplazamiento infinito dentro de un elemento en el DOM. Tengo la siguiente secuencia de comandos de puppeteer para desplazarme hasta el final para revelar todos los datos para que pueda rasparlos. La primera llamada page.evaluate funciona como se esperaba, desplazándose hasta la parte inferior y revelando el contenido adicional. Sin embargo, las llamadas posteriores no funcionan. He intentado usar await page.waitFor(2000); esperar antes de poder desplazarme más, pero parece que no funciona. ¡Ayuda a alguien!
// this script parses the data from http://covid.rcmedicrew.org/ using their /scripts/getSearch.php API // install nodejs then npm install axios const puppeteer = require('puppeteer'); const siteURL = "https://www.powerbi.com/view?r=eyJrIjoiOTcyM2JkNTQtYzA5ZS00MWI4LWIxN2UtZjY1NjFhYmFjZDBjIiwidCI6ImQ1ZmE3M2I0LTE1MzgtNGRjZi1hZGIwLTA3NGEzNzg4MmRkNiJ9"; async function callPowerBiApi(apiUrl) { const browser = await puppeteer.launch({headless: false, args: ['--auto-open-devtools-for-tabs']}); // const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); page.setDefaultNavigationTimeout(0); await page.goto(apiUrl, {waitUntil: 'networkidle0', timeout: 0}); await page.waitForSelector('.innerContainer'); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); //await page.waitFor(2000); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); await page.evaluate(() => document.querySelectorAll(".innerContainer")[1].querySelector(".bodyCells>div>div div:last-child").scrollIntoView()); }()Estaba desplazándome al elemento incorrecto, lo arreglé usando:
await page.evaluate(() => document.querySelectorAll(".innerContainer")[1] .querySelector(".bodyCells>div div:last-of-type div:last-of-type div:last-of-type") .scrollIntoView() );Sin embargo, parece que los resultados anteriores se borran cuando se desplaza hacia abajo, por lo que necesitará otra estrategia para rasparlo todo.