Wednesday, 17 October 2012
HOW TO extract Wikipedia content through its API using jQuery
Posted on 21:00 by Unknown
Wikipedia's API or more appropriately MediaWiki API, lets you programmatically fetch content & metadata related to thousands of its articles.
I built a small custom Wikipedia search application - Q-Wikipedia, to get just the first paragraph of a Wikipedia article using jQuery with help from online resources.
The REST-based Wikipedia API has many configurable options. It's easy to select the options you require using the Wikipedia API Sandbox
As I need only the first paragraph I set the value of the sections parameter to 0 (default is all)
http://en.wikipedia.org/w/api.php?action=mobileview
&format=json&page="+ keyword + "
&redirect=no§ions=0&prop=text
§ionprop=toclevel%7Clevel%7Cline%7Cnumber%7Cindex%7Cfromtitle%7Canchor
&callback=?
It has auto-completion of search terms, which was a breeze to implement using jQueryUI.
Super-script and a few other tags are removed from the Wikipedia content derived from the JSONP payload prior to injecting it into a DIV placeholder -
$('#wiki').html(json.mobileview.sections[0].text)
.find("dl,sup,.thumb,table.infobox,table.metadata,div.dablink").remove().end();
Try it out and let me know your feedback by posting a comment below.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment