Skip to content

Instantly share code, notes, and snippets.

@mackbrowne
Created October 20, 2013 18:56
Show Gist options
  • Save mackbrowne/7073718 to your computer and use it in GitHub Desktop.
Save mackbrowne/7073718 to your computer and use it in GitHub Desktop.
var items = [];
$.each($('tr'), function(i, row){
var item={}
$.each($('td', row), function(index, col){
switch(index){
case 0:
var query = $('a', col);
var size = query.size();
if(size>0){
item['Intro'] = $(query[0]).attr('href');
}
break;
case 1:
var NameSchool = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n\s*\n/g, '\n').split('\n');
item['CourseName'] = NameSchool[0];
item['CourseLink'] = $('a', col).first().attr('href');
if(NameSchool.length > 1){
item['School'] = NameSchool[1];
}
break;
case 2:
item['Instructors'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
case 3:
item['Subject'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
case 4:
item['Date'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
case 5:
item['Length'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
case 6:
item['StartDate'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
case 7:
item['Initiative'] = $(col).text().trim().replace(/ +(?= )/g,'').replace(/\n+/g, ' ');
break;
}
})
items.push(item);
});
console.log(items);
//console.log(JSON.stringify(items));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment