标签:
安装nightmare
编写1.js
运行 node 1.js
var Nightmare = require(‘nightmare‘);
var nightmare = Nightmare({ show: true })
nightmare
.goto(‘http://yahoo.com‘)
.type(‘form[action*="/search"] [name=p]‘, ‘github nightmare‘)
.click(‘form[action*="/search"] [type=submit]‘)
.wait(‘#main‘)
.evaluate(function () {
return document.querySelector(‘#main .searchCenterMiddle li a‘).href
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error(‘Search failed:‘, error);
});
标签:
原文地址:http://www.cnblogs.com/cutepig/p/5656461.html