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

194
Visualizações
puppeteer/Javascript check for network responses in a loop

Using puppeteer I am trying to achieve something where I can capture network responses on selection of a dropdown item. It does not have to be immediate, we can select all options one after another, and can use network response later as well, as long as it works smoothly.

(async () => {
  const browser = await puppeteer.launch(chromeoptions);
  const page = await browser.newPage();
  page.target().createCDPSession();
  page.setDefaultNavigationTimeout(1000000);
}

async function getAppointmentData() {
  await page.goto('go to the page URL')
  let appointmentData = [];
  await page.waitForSelector(
      "[id*=dropdownId]"
    );

  for (let option of options) {
    // Selecting an option from a dropdown trigger a network call that I need to record
    await page.select(
        "select#dropdownId",
        option?.id
      )

   /* Check for a network call that contains that option?.id or .json?details
      Sample URL >>>> https://abc.test.com/en/10.json?details  [Where 10 is options?id]
   */
  // After All Items in dropdown is selected, Want to insert response [Array of Objects] to an object like:
   appointmentData.push({
     id: options?.id;
     data: [Array of Objects]
    }]

  } // For Loop Ends

  processAppointments(appointmentData )

}

processAppointments(data) {
  /// 
}

getAppointmentData();
})();

I tried using page.on() and other methods but not helpful. can someone please help me out here? been stuck for almost one week.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your page.on should look something like:

page.on("response", response => {
  let match = response.url().match(/(\d+).json/)
  if(match){
    console.log(`option ${match[1]}`)
  }
})
about 4 years ago · Juan Pablo Isaza 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