# Wikipedia Table Scraper

I created this small script to strip the data out of tables that have hyperlinks as their <th /> elements. I was hoping to get input on code clarity and possibly simplification, efficiency is not much of an issue for me as there are not any huge tables on Wikipedia.

var arr = $('tbody').children('tr').map(function(idx) { return(idx === 0) ? { rows:$('th', this).map(function(idx) {
return {
href: $('a', this).attr('href'), title:$('a', this).text()
}
}).get()
} : {
href: $('th a', this).attr('href'), title:$('th a', this).text(),
rows: $('td', this).map(function(idx) { return$(this).text();
}).get()
}
}).get();

Here is an example of a table that this scraper can be run on.

• Could you show an example table that this can be run on? – Simon Forsberg Jun 19 '15 at 21:04
• @SimonAndréForsberg Added to question thanks for looking! You can try it out by running it in the developer console in any browser as wikipedia uses JQuery. – Mike Jun 19 '15 at 21:08