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

103
Vistas
Loading html into chrome followed by jsdom instance

I'm doing some scraping after receiving html from an api. I'd like to do the following:

  1. Open html page in chrome so I can find selectors in the console.
  2. Immediately load the same html page into a jsdom instance
  3. Drop into the repl - I can then find the right selectors in the console and test them out in a live jsdom environment to see if they work.

For 1, I have:

async function openHtml(htmlString) {

const browser = await puppeteer.launch({headless: false});
 const page = await browser.newPage();
await page.setContent(htmlString);
return;
// await browser.close();
}

The code provided with the api is:

var req = http.request(options, function (res) {
  var chunks = [];
  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);

    response = JSON.parse(body); //response.content = html, response.cookies = cookies

    const dom = new JSDOM(response.content);
    console.log(dom.window.document.querySelector("p").textContent); // "Hello world"

    openHtml(response.content);
    console.log('hi');
  });

});

req.end();

If I run the code at the command line the browser opens as expected. However, if I set a breakpoint at:

    console.log('hi');

It does not. How can I get this working?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

openHtml is an async function. So you'll have to set the method calling in await (promise) and main function to async as well.

var req = http.request(options, function (res) {
    var chunks = []
    res.on('data', function (chunk) {
        chunks.push(chunk)
    })

    res.on('end', async function () {
        var body = Buffer.concat(chunks)

        response = JSON.parse(body) //response.content = html, response.cookies = cookies

        const dom = new JSDOM(response.content)
        console.log(dom.window.document.querySelector('p').textContent) // 'Hello world'

        await openHtml(response.content)
        console.log('hi')
    })

})

req.end()
about 4 years ago · Juan Pablo Isaza Denunciar
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