-
Notifications
You must be signed in to change notification settings - Fork 3
Data Source: MIT OpenCourseWare
David: I basically took the list of courses and ran this script to create a JSON file (array of JS objects).
_See one-time **code** to grab courseList JSON_
``` javascript // one time code -- retrieve json from list
var fs = require('fs'); var cheerio = require('cheerio');
var fs = require("fs");
const departments = [ 'Aeronautics and Astronautics', 'Anthropology', 'Architecture', 'Athletics, Physical Education and Recreation', 'Biological Engineering', 'Biology', 'Brain and Cognitive Sciences', 'Chemical Engineering', 'Chemistry', 'Civil and Environmental Engineering', 'Comparative Media Studies', 'Comparative Media Studies/Writing', 'Concourse', 'Earth, Atmospheric, and Planetary Sciences', 'Economics', 'Edgerton Center', 'Electrical Engineering and Computer Science', 'Engineering Systems Division', 'Experimental Study Group', 'Global Studies and Languages', 'Health Sciences and Technology', 'History', 'Linguistics and Philosophy', 'Literature', 'Materials Science and Engineering', 'Mathematics', 'Mechanical Engineering', 'Media Arts and Sciences', 'Music and Theater Arts', 'Nuclear Science and Engineering', 'Physics', 'Political Science', 'Science, Technology, and Society', 'Sloan School of Management', 'Supplemental Resources', 'Urban Studies and Planning', 'Women's and Gender Studies', 'Writing and Humanistic Studies' ];
// Read the raw HTML of // https://ocw.mit.edu/courses/?utm_source=ocw-megamenu&utm_medium=link&utm_campaign=mclstudy // (which I copied into a file to avoid parsing a website 10000 times)
fs.readFile('./../data/mitOpenCourseWare.html', function (err, data) {
if (err) { return console.error(err); }
// Load cheerio so it can parse the HTML var $ = cheerio.load(data.toString());
// Print the title to make sure everything is working fine // Should print OCW Course Index | MIT OpenCourseWare | Free Online Course Materials
var courses = [];
/* GET THE LIST OF COURSES */ $('table[class=courseList]').each(function(i, elem) {
var courseList = $(elem).children().eq(1).children();
var length = courseList.length;
for (c in courseList) {
if (isNaN(c)) continue; // skip non-numeric rows
var course = {};
course.courseName = courseList.eq(c).children().eq(1).text().trim().replace(/\s+/g, ' ');
if (!course.courseName) continue;
course.courseId = courseList.eq(c).children().eq(0).text().trim().replace(/\s+/g, ' ');
course.url = courseList.eq(c).children().eq(0).children().eq(0)['0'].attribs.href;
course.department = departments[i];
courses.push(course);
if (c == length - 1 && i == 37)
console.log(courses);
}
})
// console.log("Asynchronous read: " + data.toString()); });
function removeWhitespace(str) { return str.replace(/\s+/g, ' '); }
</p>
</details>
---
Here's the list as of February 4, 2017.
I'm not going to show the entire list (it's 16000 lines and lags Chrome) but I'll show a few example objects in the JSON array.
<details>
<summary>_See JSON object containing MIT courses as of Feb 2017_</summary>
<p>
```javascript
[ {
"courseName": "Introduction to Aerospace Engineering and Design",
"courseId": "16.00",
"url": "/courses/aeronautics-and-astronautics/16-00-introduction-to-aerospace-engineering-and-design-spring-2003",
"department": "Aeronautics and Astronautics"
}, {
"courseName": "Exploring Sea, Space, & Earth: Fundamentals of Engineering Design",
"courseId": "16.00AJ",
"url": "/courses/mechanical-engineering/2-00aj-exploring-sea-space-earth-fundamentals-of-engineering-design-spring-2009",
"department": "Aeronautics and Astronautics"
}, {
"courseName": "Unified Engineering I, II, III, & IV (Fall 2005)",
"courseId": "16.01",
"url": "/courses/aeronautics-and-astronautics/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006",
"department": "Aeronautics and Astronautics"
}, {
"courseName": "Unified Engineering I, II, III, & IV (Fall 2005)",
"courseId": "16.02",
"url": "/courses/aeronautics-and-astronautics/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006",
"department": "Aeronautics and Astronautics"
}, {
"courseName": "Unified Engineering I, II, III, & IV (Fall 2005)",
"courseId": "16.03",
"url": "/courses/aeronautics-and-astronautics/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006",
"department": "Aeronautics and Astronautics"
}, {
"courseName": "Unified Engineering I, II, III, & IV (Fall 2005)",
"courseId": "16.04",
"url": "/courses/aeronautics-and-astronautics/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006",
"department": "Aeronautics and Astronautics"
}, {
...