We want setup and run nightmarejs example web scraper on the local machine.
If you like to code it yourself, follow the steps in the Development log
$ npm install
$ node index.js
$ npm init
$ npm install --save nightmare
Note: This will take some time
The code initializes nightmarejs, and searches a keyword "github nightmare" on your local machine. The code makes use of Javascript Promises to perform async tasks. Nightmare.js Github repo provides a good introduction and guide to learn more about nightmarejs.
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('https://duckduckgo.com')
.type('#search_form_input_homepage', 'github nightmare')
.click('#search_button_homepage')
.wait('#zero_click_wrapper .c-info__title a')
.evaluate(function () {
return document.querySelector('#zero_click_wrapper .c-info__title a').href;
})
.end()
.then(function (result) {
console.log(result);
})
.catch(function (error) {
console.error('Search failed:', error);
});
Above code has been referenced from here
$ node index.js