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

87
Visualizações
Find specific divs on page and remove before taking screenshot with puppeteer

I have a node/puppeteer script that visits a page, finds a specific div with a class, and takes a screenshot of the div. However, there are elements/nodes on the page that I'd like to delete before capturing the screenshot since they are interfering with the image, but can't seem to find the documentation on how to do so.

This is what I have so far, but can't figure out when or how to delete a given div with a specific class .ce45 for instance:

await page.setViewport({
    width: 1368,
    height: 768
});
await page.waitForSelector(`.${url.id.toLowerCase()}`).then(() => console.log('scraped', url.id.toLowerCase()));        
const component = await page.$(`.${url.id.toLowerCase()}`);     
const bounding_box = await component.boundingBox();  
await component.screenshot({
   path: `./${url.id.toLowerCase()}.png`,
   clip: {
      x: bounding_box.x,
      y: bounding_box.y,
        width: Math.min(bounding_box.width, page.viewport().width),
        height: Math.min(bounding_box.height, page.viewport().height),
   }
});

I have tried:

await page.evaluate((sel) => {
  let div_selector_to_remove = ['.ce45', '.d20', '.cc27'];
  for(sel of div_selector_to_remove){
     document.querySelector(`${sel}`).remove();
  }
});

but get the error Cannot read properties of null (reading 'remove')

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The way you have it will only remove the first for each selector (and throw error when it's not there).

Try:

page.$$eval('.ce45,.d20,.cc27', els => els.map(el => el.remove()))
about 4 years ago · Santiago Gelvez Relatório
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