Wikipedia Module in Python

 Wikipedia Module & its methods using Python



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.

Wikipedia is the largest online source of information & we can search for Wikipedia information using python a module named wikipedia itself.

Installation

To extract the information from Wikipedia we must install a python module name as wikipedia. This module has an official Wikipedia API through which we search or extract any information by entering the following command in terminal:

 pip install wikipedia 

Methods of Module

summary(): Through this method, we get a summary of any title. Its return type is <String>.

           syntax: 

wikipedia.summary(title, sentences)

    here, the title is a String type and any title can be searched by reference to that title.

            sentences is an integer type that defines how many sentences will be returned. The default value is "2".

        code: 

result = wikipedia.summary('Tesla', sentences=3)
print(result)

search(): Title and its suggestion will be returned through this search() method. Its return type is <List>.

        syntax

wikipedia.search(title, result=2)

        here, title will be the item you are searching for. With <String> type. 

        result is a number of suggestions related to the title. With <Integer> type.

        code

suggest = wikipedia .search("Cars",result=4)
print(suggest)

set_lang(): This method is used to set the resulting language ie in which language the results are to be shown. Its return type none.

        syntax:

wikipedia.set_lang(prefix)
         here, prefix will be language prefix ie for Hindi - hi & English - en of type <String>

    code:

wikipedia.set_lang('hi')
geosearch(): This method does a wikipedia search using latitude & longitude using an HTTP API described in http://www.mediawiki.org/wiki/Extension:GeoData. Its return type <List>

        syntax:

wikipedia.geosearch(latitude, longitude, title=none, result=10, radius=1000)

        code:

wikipedia.geosearch(21.76543, 71.87654, result=10)

Output

*This is output for summary() method using wikipedia module*




 Having any problem regarding any programming related stuff, feel free to dm me on my Social Media Handle Instagram


Check my Portfolioprathmeshchaudhari.me

Subscribe to my Blog & comment below !!!


Comments