-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmscraper.js
More file actions
138 lines (132 loc) · 4.4 KB
/
mscraper.js
File metadata and controls
138 lines (132 loc) · 4.4 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const fs = require('fs');
const jsoncsv = require('json-csv')
const webdriver = require('selenium-webdriver');
const safari = require('selenium-webdriver/chrome');
const sleep = require("sleep");
const config = require('./config.json');
async function runTest(){
let driver = new webdriver.Builder()
.forBrowser('safari')
.build();
const UNIVERSITIES = fs.readFileSync('universities.txt').toString().split("\n").filter((el)=>{
return el.length> 0
})
const finalList = [];
const failedList = [];
const studyField = config['studyField'] || "Computer Science";
for (var i = 0; i < UNIVERSITIES.length; i++){
const uni = UNIVERSITIES[i];
let universityNumber = i+1;
try {
await driver.get(`https://www.google.com/search?q=${uni.split(" ").join("-")}+yocket+MS+${studyField.split(" ").join("+")}`)
sleep.sleep(1);
await driver.executeScript("document.querySelector('#search a').click()");
sleep.sleep(1);
const jsScript = `function getMeInfo() {
const headingNodes = document.querySelectorAll(".statsHeading")
let credits;
let medium;
let duration;
let courseLink;
let tuitionLink;
let deadlineDetails;
for (var node of headingNodes) {
let nodeText = node && node.innerText
if(nodeText){
if(nodeText.match(/Annual Tuition Fee/g)) {
annualTuition = node.parentElement.innerText
}
else if(nodeText.match(/Course Duration/g)) {
duration = node.parentElement.innerText
}
else if(nodeText.match(/Course Credits/g)) {
credits = node.parentElement.innerText
}
else if(nodeText.match(/Delivery Medium/g)) {
medium = node.parentElement.innerText
}
else if(nodeText.match(/Course Link/g)) {
courseLink = node.parentElement.getElementsByTagName("a")[0].href
}
else if(nodeText.match(/Tuition Link/g)) {
tuitionLink = node.parentElement.getElementsByTagName("a")[0].href
}
else if(nodeText.match(/Fall/g)) {
deadlineDetails = node.parentElement.innerText
}
}
}
return { credits, duration, annualTuition, medium, courseLink, tuitionLink, deadlineDetails};
}
return getMeInfo();`
const { credits, duration, annualTuition, medium, courseLink, tuitionLink, deadlineDetails} = await driver.executeScript(jsScript)
let title = await driver.getTitle();
let yocketUrl = await driver.getCurrentUrl();
const info = {uni, universityNumber, credits, duration, annualTuition, medium, courseLink, tuitionLink, deadlineDetails, title, yocketUrl}
Object.keys(info).forEach((key)=>{
info[key] = String(info[key]).split("\n").join(" . ")
info[key]
})
console.log(`${info.universityNumber}\t\t ${info.uni}\t\t ${info.deadlineDetails}`);
finalList.push(info);
} catch (err) {
console.log("FAILED FOR UNIVERISTY " + UNIVERSITIES[i])
failedList.push({
universityNumber: i+1,
name: UNIVERSITIES[i]
}
);
const info = {uni, universityNumber, credits: "", duration: "", annualTuition: "", medium: "", courseLink: "", tuitionLink: "", deadlineDetails: "FAILED", title: "", yocketUrl: ""}
finalList.push(info);
}
}
let options = {
fields: [
{
name: 'universityNumber',
label: 'S.No.',
},
{
name: 'uni',
label: 'University',
quoted: true,
},
{
name: 'duration',
label: 'Degree Duration',
},
{
name: 'annualTuition',
label: 'Annual Tuition',
},
{
name: 'medium',
label: 'Medium',
},
{
name: 'courseLink',
label: 'Course Link',
},
{
name: 'tuitionLink',
label: 'Tuition Link',
},
{
name: 'deadlineDetails',
label: 'Deadline Details',
},
{
name: 'title',
label: 'Title',
},
{
name: 'yocketUrl',
label: 'Yocket URL',
},
],
}
let csv = await jsoncsv.buffered(finalList, options)
fs.writeFileSync(`./output/output-univs_${studyField.split(" ").join("_")}_${Date.now()}.csv` , csv);
await driver.quit();
}
runTest();