Wikipedia API: parse table as JSON?

Is it possible to parse this table as an array in a JSON array?

The result I want is something like:

[
  ["Northwest Caucasian", "Abkhaz", "าง ำ™, างำ™", "ab", "abk", "abk", "abk", "abks"], 
  [Afro-Asiatic", "Afar", "Afaraf", "aa", "aar", "aar", "aar", "aars"],
  ...
]   

      

The best I have is this , this or this , which doesn't help at all.

I need not only an ISO639 table but some other wikipedia tables as well, so I need a generic method to parse wiki tables as json. Any ideas?

+3


source to share


2 answers


Ok, I found the easiest way to use Javascript in Chrome Developer Console

$('table.sortable tr').map(function() {
    return new Array($('td', this).map(function() {
        return $(this).text()
    }).slice(2, 5).get())
}).get()

      



It's a shame wikipedia doesn't provide an API like this.

+6


source


Thanks, it helped me a lot.

You can also improve on the previous code to store the result as a json string, just wrap it in JSON.stringify()

(modern browsers only)



JSON.stringify($('table.sortable tr').map(function() {
    return new Array($('td', this).map(function() {
        return $(this).text()
    }).slice(2, 5).get())
}).get())

      

+1


source







All Articles