Is there a way to display the output from nightmareJS onto a webpage when a button is clicked using HTML, CSS, and JS?
This is my nightmareJS code:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false})
nightmare
.goto('https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux')
//.wait('#entry-content')
.evaluate(function () {
var ht = document.querySelector('#toc > ul').innerText;
//return ht[0];
//return (ht.split(/\r\n|\r|\n/).length);
//check = document.querySelectorAll('#bodyblock > ul >li').length;
//return check;
//var ht1 = document.querySelectorAll('#bodyblock > ul > li ').innerText[5];
//return ht1;
return ht;
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
return('Search failed:', error);
});
I have attempted the following:
<script>
function scrapedData(){
document.getElementById("nighmareJSOutput").innerHTML = result;
}
</script>
<body>
<div>
<p id="nighmareJSOutput"> </p>
<button onclick="scrapedData()"> click me </button>
</div>
Unfortunately, this approach did not work for me. Any tips or suggestions on how to achieve this would be greatly appreciated.