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

161
Vistas
Javascript-Resolve promise to HTML

I'm attempting to write a website with javascript that scrapes data off of another web site using puppeteer. I am able to print the value to a console, but nothing happens when I attempt to set the result to an html element. Is there something wrong with my code? The HTML code that calls it is below the javascript code.

function sleep(miliseconds) {
  var currentTime = new Date().getTime();

  while (currentTime + miliseconds >= new Date().getTime()) {}
}

async function scrapeProduct(url) {
  const puppeteer = require('puppeteer');
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(url);
  sleep(1000);
  const [el] = await page.$x('//*[@id="resultTable"]/tbody/tr[1]/td[2]/div/div[1]/font[1]');
  const txt = await el.getProperty('innerHTML');
  const rawTxt = await txt.jsonValue();
  browser.close();
  return rawTxt;
}

function runScript() {
  scrapeProduct('https://www.purpleair.com/sensorlist?key=HIGZAD9XGVDEMVVZ&show=37253')
    .then(function(result) {
      //console.log(result); 
      document.getElementById("p1").innerHTML = result;
    });
}
runScript()
<html>

<head>
  <script type="text/javascript" src="purpleAir.js"></script>
</head>

<body>

  <title>Test</title>
  <h1></h1>
  <p id="p1">Hello World!</p>

  <script>
    runScript()
  </script>

  <form>
  </form>
</body>

</html>

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