Wikipedia Summary Python API

Introduction

Imagine you want to get chemical properties of Oxygen. There should be an article about Oxygen on Wikipedia. How about Microsoft corporation ? Who is the CEO ? Where is the headquarter located ? Again, Microsoft is so popular so there must be an article about it on Wikipedia. The good news is that each good quality article on Wikipedia there is a summary table on the right side of the page. In this article I am going to demonstrate how to extract such information easily using few API calls. I am going to use Python but you can use any language you prefer. Let us get started…

RapidAPI

Follow the steps below to access the API.

  • Go to https://rapidapi.com/8bitavenue-wikipedia-squad/api/wikiapi
  • If you do not have a RapidAPI account register a new account. You just need an email address. It is free and RapidAPI is a legit business so there is no security risk in doing that. RapidAPI is relatively a new company but it is the dominant market place for APIs.
  • Click subscribe. Currently there is only one plan which is totally free. No credit card is needed and if you reach the maximum number of requests per month there is a hard limit so nothing is going to be charged.
  • In order to subscribe to any plan you need to have a RapidAPI app. If you do not have one click on My Apps on the top right corner and create one. Once you are done you can select that app before subscribing to the API
  • At this point you can explore the list of available APIs and test any endpoint from RapidAPI UI. You can even copy and paste code samples using your preferred programming language.

Using the API

For demonstration let us try to extract headline news from Wikipedia. Here is a code snippet to do that.

Note that the language is hardcoded to English (en in this case). To try other languages (if supported) just use the language you want for example ar for Arabic. If everything is ok you should get an output like…

Here is another example where we will be extracting information about battle field tanks. First we need to know what tanks the API supports. To do that use the code below…

The output will look like…

Now let us get the tank information for the M1 Abrams tank. Use the following code…

If everything is ok you should get an output like…

That is it for today. Just explore the list of available APIs for a topic. Currently there are 45 endpoints supporting various topics such as biography, business, science, geography, sports, education, engineering, military, history and animals. If you have question please leave a comment blow.

Tags:,

Add a Comment

Your email address will not be published. Required fields are marked *