I want to show my output of my js code in a html website

I want to show the output of this js code(main.js) in the body of this HTML code(index.html) how do I do it ? I want the output of the js code to be written int the body part of the HTML. If you have any ideas or tips please help ! and I am only a beginner so if you can please explain in simple and easy words thank you !!


const puppeteer = require('puppeteer')

async function scrapeProduct(url) {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(url);

  const [el] = await page.$x('//*[@id="root"]/div/div/div/div[3]/div[1]/div/div/div/div/div[2]/a/img');
  const src = await el.getProperty('src');
  const srcTxt = await src.jsonValue();

  const [el2] = await page.$x('//*[@id="root"]/div/div/div/div[3]/div[2]/div[1]/div/h1/span');
  const txt = await el2.getProperty('textContent');
  const title = await txt.jsonValue();
  const [el3] = await page.$x('//*[@id="a-autoid-25-announce"]/div/div/div[2]/div[1]/div[2]');
  const txt2 = await el3.getProperty('textContent');
  const price = await txt2.jsonValue();

  console.log({srcTxt, title, price});



the output :

 srcTxt: 'https://m.media-amazon.com/images/I/71YlH-4MUQL.jpg',
 title: 'New Apple iPhone 12 Pro (128GB, Graphite) [Locked] + Carrier Subscription',
 price: '+$55.00/mo'

the HTML :

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  // i want the output to be here

Read more here: https://stackoverflow.com/questions/64402662/i-want-to-show-my-output-of-my-js-code-in-a-html-website

Content Attribution

This content was originally published by skyy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: