-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrxNightmare.js
106 lines (90 loc) · 2.89 KB
/
rxNightmare.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var Rx = require('rxjs/Rx')
// var r1 = Rx.Observable.of(1, 2, 3)
// r1.map((x) => {console.log(x)})
// var r2 = Rx.Observable.fromPromise(Promise.resolve(10))
// r2.subscribe({
// next: y => console.log(y + 10),
// complete: () => console.log('done'),
// }).subscribe({
// n
// })
// 1-------------------------------------------------------------------
// Test rxJs Working
// 1-------------------------------------------------------------------
// var Nightmare = require('nightmare');
// var nightmare = Nightmare({
// show: true,
// })
// var night1 = function() {
// return Promise.resolve(
// nightmare
// .goto("https://www.alibaba.com/")
// .type('.ui-searchbar-keyword', 'chair')
// .click('.ui-searchbar-submit')
// .wait(2000)
// .then(() => {
// console.log('closing nightmare down')
// return nightmare.end()
// })
// .then(() => {
// return 'hello my friend from the other side';
// })
// )
// }
// var rxNight = Rx.Observable.fromPromise(night1());
// rxNight.subscribe({
// next: x => console.log('got value ' + x),
// error: err => console.error('something wrong occurred: ' + err),
// complete: () => console.log('done'),
// });
// 2-------------------------------------------------------------------
var Nightmare = require('nightmare');
var extract = require('./extractors.js');
var proxyNightmare = Nightmare({
switches: {
'proxy-server': 'fr.proxymesh.com:31280' // set the proxy server here ...
},
// webPreferences: {
// partition: 'nopersist', // causes errors. page does not load fully
// session:clearCache(() => {console.log('cache cleared')}), // does not work...
// },
show: true
});
Nightmare.action('clearCache',
function(name, options, parent, win, renderer, done) {
parent.respondTo('clearCache', function(done) {
win.webContents.session.clearCache(done);
});
done();
},
function(message, done) {
this.child.call('clearCache', done);
});
var night1 = function() {
return Promise.resolve(
proxyNightmare
// .clearCache() // page fails to render. just a blank white screen appears.
.authentication('jammie', 'jameso01')
.useragent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36")
.goto("https://www.alibaba.com/")
.type('.ui-searchbar-keyword', 'marker pen')
.wait(1000)
.click('.ui-searchbar-submit')
.wait(2000)
.evaluate(extract.alibaba)
.then((x) => {
console.log('printing out list of results now...');
console.log(x)
return nightmare.end()
}).catch((err) => {console.log(err)})
.then(() => {
return 'hello my friend from the other side';
}).catch((err) => {console.log(err)})
)
}
var rxNight = Rx.Observable.fromPromise(night1());
rxNight.subscribe({
next: x => console.log('got value ' + x),
error: err => console.error('something wrong occurred: ' + err),
complete: () => console.log('done'),
});