How to Use Python Wikipedia Module

Contents
In this article, you will learn how to use Python wikipedia module.
Python Wikipedia Module
The Python Wikipedia module is a third-party Python library that provides an easy-to-use wrapper for the Wikipedia API. This module allows you to easily search for and retrieve information from Wikipedia pages using Python.
To use Python’s Wikipedia module, you need to install it first. You can do that by running the following command in your command prompt or terminal:
pip install wikipedia
Once installed, you can use the module by importing it into your Python code:
import wikipedia
Here are some basic functions you can use with the Wikipedia module:
-
To search for a specific page on Wikipedia:
results = wikipedia.search("Python programming language")
This will return a list of page titles that match the search query.
-
To get the summary of a page:
summary = wikipedia.summary("Python programming language")
This will return a string containing the summary of the page.
-
To get the full text of a page:
page = wikipedia.page("Python programming language") content = page.content
This will return a string containing the full text of the page.
-
To get the list of links on a page:
page = wikipedia.page("Python programming language") links = page.links
This will return a list of links on the page.
-
To get the categories of a page:
page = wikipedia.page("Python programming language") categories = page.categories
This will return a list of categories that the page belongs to.