Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda