-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (42 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Command Line Args
const commandLineArgs = require('command-line-args')
const optionDefinitions = [
{ name: 'keyword', alias: 'k', type: String, defaultOption: true },
]
const options = commandLineArgs(optionDefinitions)
if (!options.hasOwnProperty("keyword")) {
console.error('Keyword not provided')
return;
}
//
// File System Utils
const fs = require('fs');
// Nightmare
var Nightmare = require('nightmare');
var nightmare = Nightmare({
show: true,
openDevTools: {
mode: 'detach'
},
dock: true,
});
nightmare
.goto('https://duckduckgo.com')
.type('#search_form_input_homepage', options.keyword)
.click('#search_button_homepage')
.wait('.content-wrap')
.then(function () {
return nightmare.evaluate(function() {
return document.querySelector('body').innerHTML;
})
})
.then(function(page) {
fs.writeFileSync(options.keyword+'.html', page);
})
.then(function (result) {
return nightmare.end();
})
.catch(function (error) {
console.error('Search failed:', error);
});
//