概要
phantomjsを使いやすくしたようなライブラリ。
リファレンス
https://github.com/segmentio/nightmare#api
インストール
npm install nightmare``
``node example.js
デバッグ
set DEBUG=nightmare & node C:\document\js\nightmare-test.js
DEBUG=nightmare*
サンプル [DuckDuckGoで検索]
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);
});