Wikipedia Module & its methods using Python
Installation
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>wikipedia.geosearch(latitude, longitude, title=none, result=10, radius=1000)
code:
wikipedia.geosearch(21.76543, 71.87654, result=10)
Output
Having any problem regarding any programming related stuff, feel free to dm me on my Social Media Handle ➡Instagram
Comments
Post a Comment