DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Spandan
Spandan

Posted on

Extracting info from Wikipedia in python

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 !

Top comments (3)

Collapse
 
wjplatformer profile image
Wj • Edited on

Although getting from a Wikipedia API is fine, but not all information found on websites would provide you with an API. An API is a source of info scraped from a website or retrieved from a database such as SQL.

An example Databases include :

  1. The GH Rest API and
  2. a web-scraped GH API by LogSkele called Gitcollect.
  3. This Wikipedia python module

So if a website has no API, you can still get information from it!

Using BS4 or Beautiful Soup 4 A python module to web scrape information from a website where you can do requests. It's a really useful module to add to your skillset!
You can use Web Scraping!

Collapse
 
spandan profile image
Spandan

Yeah thanks for sharing, I know that but this script is for using just the Wikipedia module.

Collapse
 
wjplatformer profile image
Wj

ok then πŸ˜€

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.