This repository was archived by the owner on Aug 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.js
More file actions
53 lines (46 loc) · 1.32 KB
/
query.js
File metadata and controls
53 lines (46 loc) · 1.32 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
var http = require("http");
// Utility function that downloads a URL and invokes
// callback with the data.
function download(url, callback) {
http.get(url, function(res) {
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on("end", function() {
callback(data);
});
}).on("error", function() {
callback(null);
});
}
var cheerio = require("cheerio");
var url = "http://critique.gatech.edu/course.php?id=CS2050"
download(url, function(data) {
if (data) {
var $ = cheerio.load(data);
var json = {};
var tdArr = [];
var professorInfo = [];
var Pclass = {};
$('td').each(function() {
//tdArr = $(this).text();
tdArr.push($(this).text());
console.log($(this).text());
});
//var tdArr = $('td').$(this).text().toArray();
json.gpa = tdArr[1] + " A:" + tdArr[2] + "%" + " B:" + tdArr[3] + "%"+ " C:" + tdArr[4] + "%"+ " D:" + tdArr[5] + "%"+ " F:" + tdArr[6] + "%";
json.CRN = url.split("=")[1];
json.pInfo = professorInfo;
//console.log(tdArr);
console.log(json);
console.log("done");
// var fs = require('fs');
// var stream = fs.createWriteStream("info.json");
// stream.once('open', function(fd) {
// stream.write(data);
// stream.end();
// });
}
else console.log("error");
});