Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python Typer Module
Next article icon

Wikipedia module in Python

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Internet is the single largest source of information, and therefore it is important to know how to fetch data from various sources. And with Wikipedia being one of the largest and most popular sources for information on the Internet.

Wikipedia is a multilingual online encyclopedia created and maintained as an open collaboration project by a community of volunteer editors using a wiki-based editing system.
In this article, we will see how to use Python’s Wikipedia module to fetch a variety of information from the Wikipedia website.

Installation

In order to extract data from Wikipedia, we must first install the Python Wikipedia library, which wraps the official Wikipedia API. This can be done by entering the command below in your command prompt or terminal:

pip install wikipedia

Getting Started

Getting the summary of any title

Summary of any title can be obtained by using summary method. 

Syntax : wikipedia.summary(title, sentences)
Argument : 
Title of the topic 
Optional argument: setting number of lines in result.
Return : Returns the summary in string format. 
 

Code :  

Python3

# importing the module
import wikipedia
 
# finding result for the search
# sentences = 2 refers to numbers of line
result = wikipedia.summary("India", sentences = 2)
 
# printing the result
print(result)
                      
                       

Output :

India (Hindi: Bh?rat), officially the Republic of India (Hindi: Bh?rat Ga?ar?jya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country, and the most populous democracy in the world. 

Searching title and suggestions

Title and suggestions can be get by using search() method. 

Syntax : wikipedia.search(title, results)
Argument : 
Title of the topic 
Optional argument : setting number of result.
Return : Returns the list of titles. 
 

Code :  

Python3

# importing the module
import wikipedia
 
# getting suggestions
result = wikipedia.search("Geek", results = 5)
 
# printing the result
print(result)
                      
                       

Output : 

['Geek', 'Geek!', 'Freaks and Geeks', 'The Geek', 'Geek show']

Getting Full Wikipedia Page Data

The page() method is used to get the contents, categories, coordinates, images, links and other metadata of a Wikipedia page.

Syntax : wikipedia.page(title)
Argument : Title of the topic.
Return : Return a WikipediaPage object. 
 

Code :  

Python3

# importing the module
import wikipedia
 
# wikipedia page object is created
page_object = wikipedia.page("india")
 
# printing html of page_object
print(page_object.html)
 
# printing title
print(page_object.original_title)
 
# printing links on that page object
print(page_object.links[0:10])
                      
                       

Output :

“bound method WikipediaPage.html of “WikipediaPage ‘India'”> 
India 
[‘.in’, ’10th BRICS summit’, ’11th BRICS summit’, ’12th BRICS summit’, ’17th SAARC summit’, ’18th SAARC summit’, ‘1951 Asian Games’, ‘1957 Indian general election’, ‘1962 Indian general election’, ‘1982 Asian Games’] 

Changing language of Wikipedia page

The language can be changed to your native language if the page exists in your native language. Set_lang() method is used for the same. 

Syntax : wikipedia.set_lang(language)
Argument : prefix of the language like for arabic prefix is ar and so on.
Action performed : It converted the data into that language default language is english. 
 

Code :  

Python3

# importing the module
import wikipedia
 
# setting language to hindi
wikipedia.set_lang("hi")
 
# printing the summary
print(wikipedia.summary("India"))
                      
                       

Output :

python-wikipedia


 



Next Article
Python Typer Module

R

rakshitarora
Improve
Article Tags :
  • Python
  • python-modules
Practice Tags :
  • python

Similar Reads

  • TextaCy module in Python
    In this article, we will introduce ourselves to the TextaCy module in python which is generally used to perform a variety of NLP tasks on texts. It is built upon the SpaCy module in Python.  Some of the features of the TextaCy module are as follows:It provides the facility of text cleaning and prepr
    13 min read
  • Python Module Index
    Python has a vast ecosystem of modules and packages. These modules enable developers to perform a wide range of tasks without taking the headache of creating a custom module for them to perform a particular task. Whether we have to perform data analysis, set up a web server, or automate tasks, there
    4 min read
  • Python Typer Module
    Typer is a library for building powerful command-line interface applications in the easiest way. It is easier to read and the simplest way to create a command line application rather than using the standard Python library argparse, which is complicated to use. It is based on Python 3.6+ type hints a
    5 min read
  • Python Fire Module
    Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w
    3 min read
  • Python String Module
    The string module is a part of Python's standard library and provides several helpful utilities for working with strings. From predefined sets of characters (such as ASCII letters, digits and punctuation) to useful functions for string formatting and manipulation, the string module streamlines vario
    4 min read
  • Python Modules
    Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work. In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we
    7 min read
  • Docopt module in Python
    Docopt is a command line interface description module. It helps you define a interface for a command-line application and generates parser for it. The interface message in docopt is a formalized help message. Installation You can install docopt module in various ways, pip is one of the best ways to
    3 min read
  • Keyword Module in Python
    Python provides an in-built module keyword that allows you to know about the reserved keywords of python. The keyword module allows you the functionality to know about the reserved words or keywords of Python and to check whether the value of a variable is a reserved word or not. In case you are una
    2 min read
  • Update List in Python
    In Python Programming, a list is a sequence of a data structure that is mutable. This means that the elements of a list can be modified to add, delete, or update the values. In this article we will explore various ways to update the list. Let us see a simple example of updating a list in Python. [GF
    3 min read
  • Python word2number Module
    Converting words to numbers becomes a quite challenging task in any programming language. Python's Word2Number module emerges as a handy solution, facilitating the conversion of words denoting numbers into their corresponding numerical values with ease. In this article, we will see what is the word2
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences