Created
October 20, 2013 18:56
-
-
Save mackbrowne/7073718 to your computer and use it in GitHub Desktop.
Jquery Crawler for http://www.class-central.com/courses/upcoming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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