Reputation: 1617
I am trying to search for a given term on the Wikipedia API and am able to retrieve a list of titles and snippets, but I want the JSON to also include the Wikipedia "curid" or "pageid" so I can use that for links.
Here is the (unhelpful) documentation as far as I can tell, and here is what I have so far:
var jsonresult=null;
$.ajax({
dataType: "jsonp",
url: "http://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch=Einstein&callback=?",
success: function(result){
console.log(result);
jsonresult = result;
printAjax(result);
},
error: function(error){
console.log("oh no");
}
});
}
I don't know how to change the API request URL.
Upvotes: 1
Views: 1872
Reputation: 121
Alternatively, you could use the url query in the ajax request and append the percent encoded title from the returned object encodeURI(data["query"]["search"][index]["title"])
to "https://en.wikipedia.org/wiki/"
and use that for your page links.
Upvotes: 0
Reputation: 7036
To get "pageid" try query with generator instead list, and use extracts property for text snippet:
https://en.wikipedia.org/w/api.php?action=query&generator=search&utf8=1&gsrsearch=Einstein&prop=extracts&exintro=1&exlimit=20&exchars=200
Upvotes: 3