Wikipedia is known for its vast area of contents which everyone can share easily. It is something like an online free encyclopedia and the contents in Wikipedia can be edited by anyone around the world. This article focuses on extracting Wikipedia contents of any personality or about anything using simple Python Programming.
module wikipedia
Python has many modules that are flexible to use in real-world applications. To extract Wikipedia contents, python has a module called "wikipedia". This module helps to fetch content from Wikipedia and to display result in your console screen.
Installing Module
The module can be installed by using,
pip install wikipedia
Fetching Content
The contents can be fetched by importing the module "wikipedia" and using the function summary( ).
import wikipedia
print(wikipedia.summary("ElonMusk" , sentences = 10))
The above code will result in Wikipedia content of "Elon Musk", limited to 10 lines.
The parameter "sentences" is optional inside wikipedia.summary( ), where you can specify any number of lines to be printed on the resulting content.
Changing the language of the fetched contents
The contents fetched can be translated to any languages using,
import wikipedia
wikipedia.set_lang( "hi" )
print(wikipedia.summary( "Mark Zuckerberg" )
In the above code, wikipedia.set_lang( language ) is used to convert contents from default language to the language passed inside the argument.
Comments
Post a Comment