Created
December 15, 2016 19:08
-
-
Save mackermedia/9a0ca15b6a0b246324b63574fce72079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Nightmare = require('nightmare'); | |
var nightmare = Nightmare({ show: true }); | |
var fs = require('fs'); | |
var util = require('util'); | |
var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags : 'w'}); | |
var log_stdout = process.stdout; | |
console.log = function(d) { // | |
log_file.write(util.format(d) + '\n'); | |
log_stdout.write(util.format(d) + '\n'); | |
}; | |
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment