Extracting info from Wikipedia in python

Spandan Sehgal - Dec 31 '21 - - Dev Community

Intro

Hi there, as you read in this post we are going to do some data extracting from wikipedia in python. This project is very simple and fun to build and after reading this post please do comment down that what should I build next .

Modules required

  1. wikipedia : This module helps us to get data from wikipedia using python.

Installation

pip install wikipedia
Enter fullscreen mode Exit fullscreen mode

Let's Code

First we will import the required module, so lets do it quickly

# importing the module
import wikipedia
Enter fullscreen mode Exit fullscreen mode

Now we will ask the user to enter the subject he wants to search

search = input("What do you want to search ? \n")
Enter fullscreen mode Exit fullscreen mode

Now we will use the input to search data from wikipedia

# finding result for the search
''' sentences = 2 refers to numbers of line the number may vary it is according to you '''
result = wikipedia.summary(search, sentences = 2)
Enter fullscreen mode Exit fullscreen mode

Now we will finally print the result

# printing the result
print(result)
Enter fullscreen mode Exit fullscreen mode

And with that done we have successfully completed another project.
That's it for today stay safe and do take very good care of yourselves and VERY HAPPY NEW YEAR !

And pls do comment what can I make I next post and feel free to ask/suggest something in the comments section.

Happy Coding !

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .