Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
Puppeteer Question: I'm Screenshotting A Series of Pages. Can I Use Each Page URL as the Image Name?

I have a problem with a Puppeteer script I'm writing. I've gotten it to do 90% of what it needs to do, which is use the sitemap page for any given site and go to each page before taking a full-page screenshot. It also spits out a console.log of a massive array with all of the site URLs. What I need to do and can't get right is to pull the page URL for each page it opens during its for loop and use that as the name for the screenshot. So like if it goes to google.com, picture 1 is called "google.com/.png", then "google.com/dogpictures.png" etc.

I'm including it below, I'd love to hear any feedback:

const puppeteer = require("puppeteer");

(async () => {
    'use strict'
 
    const smta = require('sitemap-to-array')
    const options = { returnOnComplete: true}
    const sitemapUrl = 'https:____.org/page-sitemap.xml'
     
    smta(sitemapUrl, options, (error, list) => {
      if (error) {
        console.error(error)
      } else {     

        console.log(list)
        useSitemapWithPuppeteer(list);
      }
    })

  const useSitemapWithPuppeteer = async (array) => {  

  const urls = array.map(obj => obj.loc);
  
  const browser = await puppeteer.launch({
    headless: false,
    defaultViewport: null,
  });
  
  for (let i = 0; i < urls.length; i++) {  
    const url = urls[i];
    const page = await browser.newPage();
    page.setDefaultNavigationTimeout(0);
    await page.goto(`${url}`, { waitUntil: "networkidle2" });
    const currentURL = page.url;
    await page.screenshot({ path: "test" + i + ".png", fullPage: true });
    
  }
  await browser.close();
  
}})();
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda