You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 10, 2024. It is now read-only.
var html2json = require('html2json').html2json;
var json2html = require('html2json').json2html;
var fs = require ('fs');
// load the HTML from a file
var htmldoc = fs.readFileSync('./index2.html', "utf8");
console.log(htmldoc);
// convert the innerHTML of the body to JSON
var jsondoc = html2json(htmldoc.body.innerHTML);
console.log(jsondoc);
with the following output:
<!doctype html>
<html lang="en">
<head>
<title>Test Page</title>
<meta charset="utf-8" >
</head>
<body>
<div id="1" class="foo">
<h2>sample text with <code>inline tag</code></h2>
<pre id="demo" class="foo bar">foo</pre>
<pre id="output" class="goo">goo</pre>
<input id="execute" type="button" value="execute"/>
</div>
</body>
</html>
[stdin]:12
var jsondoc = html2json(htmldoc.body.innerHTML);
^
TypeError: Cannot read property 'innerHTML' of undefined
at [stdin]:12:38
at Script.runInThisContext (vm.js:132:18)
at Object.runInThisContext (vm.js:315:38)
at Object.<anonymous> ([stdin]-wrapper:10:26)
at Module._compile (internal/modules/cjs/loader.js:1236:30)
at evalScript (internal/process/execution.js:98:25)
at internal/main/eval_stdin.js:29:5
at Socket.<anonymous> (internal/process/execution.js:211:5)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1244:12)
[Finished in 0.249s]
I'm using the following HTML page:
with the following code:
with the following output:
What am I missing?☹️