1

I want to create and manipulate several HTML files with JavaScript and NodeJS. The usual way to update HTML files is to include an update script at the top, but I want to create multiple HTML files with one JS file. I have a list with the necessary data to process. It contains the names for the HTML files and the data to put in.

My idea was to use a model.html file, which contains the data, that will be included in all of the files. This model file will be copied and renamed to the necessary file. Then I want to load it with a NodeJS module or any other way fit, so it will be recognized as "document" as if the script was included in the file. Then I want to manipulate it with plain JS. A for loop should iterate through the list and create the file, load it as "document", manipulate it and then go to the next file.

Is this possible?

Kaushal shah
  • 557
  • 3
  • 12
neolith
  • 699
  • 1
  • 11
  • 20

1 Answers1

1

If you want to just parse the HTML and get the document and operate on it you can check https://cheerio.js.org/

If you want to execute the Javascript also then you need to use Headless browsers like Headless Chrome

karthikdivi
  • 3,466
  • 5
  • 27
  • 46