-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
49 lines (46 loc) · 1.71 KB
/
Copy pathexample.js
File metadata and controls
49 lines (46 loc) · 1.71 KB
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
var searches = ['/schools/private-schools/vision-afrika-primary-school.html',
'/tutors/hartenbos-eden-christelike-akademie.html',
'/schools/private-schools/west-coast-music-academy.html',
'/schools/private-schools/edu-excellence-private-remedial-school-cape-town.html'];
var schoolArray = [[],[]]
var page = require('webpage').create();
function follow(search, callback) {
page.open('https://www.schoolguide.co.za' + search, function (status) {
// console.log('https://www.schoolguide.co.za/schools/private-schools/' + search)
if (status === 'fail') {
console.log(search + ': ?');
} else {
console.log("getting school info");
var name = page.evaluate(function () {
return document.querySelector('article div div h1 span').innerText;
});
console.log(name);
var school = page.evaluate(function () {
return document.querySelector('title').innerText;
});
var data = page.evaluate(function () {
return document.querySelector('tbody tr td span a').href;
});
console.log(search + ' email: ' + data);
schoolArray[0].push(search + ' school: ' + school);
schoolArray[1].push(search + ' email: ' + data);
// console.log('success')
}
page.close();
callback.apply();
});
}
function process() {
if (searches.length > 0) {
var search = searches[0];
searches.splice(0, 1);
follow(search, process);
} else {
var fs = require('fs');
var path = 'output.csv';
var content = schoolArray;
fs.write(path, content, 'w');
phantom.exit();
}
}
process();