Search code examples
javascriptwikipedia-apimediawiki-api

Random article API call is returning User talk pages?


I'm trying to pull a random article from the WikiMedia API, but my code seems to only grab User talk pages...

$(document).ready(function(){
  $.getJSON("http://en.wikipedia.org/w/api.php?action=query&generator=random&prop=extracts&exchars=500&format=json&callback=?", function (data) {
    console.log(data.query.pages);
  });
});

I read that "generator=random" pulls a random article, but that does not seem to be the case. How do I get it working as intended?


Solution

  • If you want to get only pages in namespace 0, you need to specify the rnnamespace parameter. And since you're using list=random as a generator, it's spelled as grnnamespace: