I want to loop over each li> in ul> and later add them into an array. How should I go about creating a for loop to return each li and put them into array. Getting the li in a loop is where I got stuck.
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false })
nightmare
.goto('https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux')
.wait(500)
.evaluate(function () {
var ht = document.querySelector('#toc > ul > li.toclevel-1.tocsection-5 > ul
').innerText;
return ht;
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
Output:
PS C:\scrapping> node .\2.js
5.1 RHEL 2.1
5.2 RHEL 3
5.3 RHEL 4
5.4 RHEL 5
5.5 RHEL 6
5.6 RHEL 7
PS C:\scrapping>