Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!