neolith
neolith

Reputation: 819

How load several HTML files as "document" and then manipulate them with Javascript?

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?

Upvotes: 1

Views: 238

Answers (1)

karthikdivi
karthikdivi

Reputation: 3643

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

Upvotes: 1

Related Questions