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.
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 the summary of any title
Summary of any tittle can be obtained by using
Syntax : wikipedia.summary(title, sentences)
Title of the topic
Optional argument: setting number of lines in result.
Return : Returns the summary in string format.
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
Syntax : wikipedia.search(title, results)
Title of the topic
Optional argument : setting number of result.
Return : Returns the list of titles.
['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.
“bound method WikipediaPage.html of “WikipediaPage ‘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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Fetching text from Wikipedia's Infobox in Python
- Voice search Wikipedia using Python
- Web scraping from Wikipedia using Python - A Complete Guide
- MySQL-Connector-Python module in Python
- twitter-text-python (ttp) module - Python
- Import module in Python
- OS Module in Python with Examples
- struct module in Python
- Secrets | Python module to Generate secure random numbers
- Python calendar module | formatmonth() method
- Python | Writing to an excel file using openpyxl module
- Count frequencies of all elements in array in Python using collections module
- OS Path module in Python
- Stack and Queue in Python using queue Module
- Testing in Python using doctest module
- Python | ASCII art using pyfiglet module
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Plotting charts in excel sheet using openpyxl module | Set - 1
- Python | Convert Image to Pdf using img2pdf module
- Python | Plotting charts in excel sheet using openpyxl module | Set – 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.