<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\758211560\46blogName\75Tech+Tips,+Tricks+%26+Trivia\46publishMode\75PUBLISH_MODE_BLOGSPOT\46navbarType\75BLUE\46layoutType\75CLASSIC\46searchRoot\75http://mvark.blogspot.com/search\46blogLocale\75en\46v\0752\46homepageUrl\75http://mvark.blogspot.com/\46vt\75-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
A seasoned developer's little discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


HOW TO extract Wikipedia content through its API using jQuery


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&sections=0&prop=text
&sectionprop=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.


Labels: , ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

Posted by Blogger onlinearticles | 6/09/2013 03:36:00 PM

will you please provide the full source code for this...

thanks . for sharing..    



Posted by Blogger Anil | 6/09/2013 04:03:00 PM

The JavaScript code to access the Wikipedia API is right in the HTML page source. Right click on the page & choose View Page Source to go through it.    



»

Post a Comment